Thread Starter
Jyoti
(@rieiirir)
I got a function to set the hint for viewport featured image only one time. It will not repeat if page contains multiple featured image as my target is for VPI.
add_filter(‘wp_lazy_loading_enabled’, ‘__return_false’);
function add_featured_image_attribute( $attr, $attachment, $size ) { // Check if the current page is a single post page
if ( is_single() ) { global $post; static $count = 0;
// Increment the count of featured images displayed $count++;
// Add the attribute only to the first featured image if ( $count === 1 && has_post_thumbnail( $post->ID ) ) { $attr[‘fetchpriority’] = ‘high’; } } return $attr;}add_filter( ‘wp_get_attachment_image_attributes’, ‘add_featured_image_attribute’, 10, 3 );
