By applying the featured image optimization snippet, the Largest Contentful Paint (LCP) improved dramatically — dropping from 3.9 s to 1.7 s on mobile.
That single change boosted the overall performance score from 88 → 98, proving how much impact a properly prioritized featured image can have on Core Web Vitals.

The snippet below:
-
Disables WordPress’s default lazy-loading for the featured image
-
Forces early loading with
loading="eager" -
Adds
fetchpriority="high"to tell the browser to prioritize this image -
Keeps full
srcsetandsizesfor responsive display -
Automatically sets an
alttag (using the post title if none exists)
Add This to functions.php
/**
* Optimize Featured Image for Better LCP
*
* This snippet disables lazy loading for the featured image
* and adds loading="eager" + fetchpriority="high" to improve LCP.
*
* Use the shortcode [featured_image_lcp] anywhere inside your post or template.
*/
function lcp_featured_image_shortcode() {
if ( is_singular() && has_post_thumbnail() ) {
$thumb_id = get_post_thumbnail_id();
$alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );
$alt = $alt ? esc_attr( $alt ) : esc_attr( get_the_title() );
$src_full = wp_get_attachment_image_url( $thumb_id, 'full' );
$srcset = wp_get_attachment_image_srcset( $thumb_id, 'full' );
$sizes = wp_get_attachment_image_sizes( $thumb_id, 'full' );
return '<img
src="' . esc_url( $src_full ) . '"
loading="eager"
fetchpriority="high"
data-no-lazy="1"
alt="' . $alt . '"
srcset="' . esc_attr( $srcset ) . '"
sizes="' . esc_attr( $sizes ) . '"
width="100%" height="auto" class="featured-lcp-img">';
}
return '';
}
add_shortcode( 'featured_image_lcp', 'lcp_featured_image_shortcode' );
How to Use It
After adding the code to your theme’s functions.php, simply place this shortcode anywhere inside your post or template:
[featured_image_lcp]
-
Instant visual feedback: The main image appears right away.
-
Better Core Web Vitals: Improves your LCP score and boosts SEO.
-
Clean HTML output: No extra wrappers or divs.
-
Accessibility-friendly: Auto
altfallback to the post title. -
Plug-and-play: Works with any WordPress theme.
🚀 Pro Tip
Use this for the hero or main featured image above the fold only. Keep lazy loading active for other images further down the page to save bandwidth and resources.