Add fetchpriority=”high” to the VPI image for improve LCP

[ad_1]

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 );

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer