Optimize Your Featured Image for Better LCP (Eager + High Priority)

When your featured image is the largest element on the page, it directly affects your Largest Contentful Paint (LCP) — one of the key Core Web Vitals. If that image loads too late, your page speed score drops, your visitors wait longer, and your SEO suffers. This small snippet fixes that by loading your featured image as early as possible.
Author:
|
CTO of
Quanta Digital Agency
Published
If you'd like someone to take care of your marketing, I'm here to help, Click Here

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.

before after lcp

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 srcset and sizes for responsive display

  • Automatically sets an alt tag (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 alt fallback 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Practical Web Tutorials for WordPress Designers, Developers & SEO Experts on My YouTube Channel
Do you want
 more traffic from Google?

About Peyman Farahani

Peyman Farahani is CTO of Quanta Digital Agency

As a digital problem-solver with a focus on SEO, WordPress, and performance-first design, I’ve helped clients achieve real digital results.

I connect creativity with execution — exploring market gaps, shaping clear ideas, and building solutions that actually make an impact.