wp_get_attachment_image_attributes ignores fetchpriority
-
Hello,
I’m trying to add
fetchpriority="high"to my featured image using the following code:add_filter( 'wp_get_attachment_image_attributes', function ( $attr ) { if ( isset( $attr['class'] ) && strpos( $attr['class'], 'wp-post-image' ) !== false ) { $attr['fetchpriority'] = 'high'; $attr['loading'] = 'eager'; $attr['data-test'] = 'YES'; } return $attr; }, 999 );The featured image correctly receives:
loading="eager" data-test="YES"but
fetchpriority="high"is removed from the final HTML.I also tested with a custom attribute named
fetchpriority-test, and it is removed as well, while other custom attributes are preserved.I have already contacted Astra Pro support and WP Rocket support, and neither seems to be the source of the issue.
Is WordPress sanitizing or overriding
fetchprioritysomewhere afterwp_get_attachment_image_attributesruns? What is the correct way to forcefetchpriority="high"on a featured image?Thank you.
You must be logged in to reply to this topic.