Skip to content

WordPress lazy loading attributes — keeping LCP fast

WordPress adds loading="lazy" to every image since 5.5, which can hurt LCP when the hero image gets lazy-loaded. How to control the attribute and protect Core Web Vitals.

WordPress 5.5 added loading="lazy" to every image by default, which sounds like a Core Web Vitals win — and is, except for the hero image. When the largest contentful paint candidate gets loading="lazy", the browser delays the request until the layout settles, and LCP regresses by 200-800 ms. WordPress 5.9 added logic to skip the attribute on the first image, but the heuristic is fragile and most production sites get bitten at least once.

What’s happening

WordPress’s wp_filter_content_tags() (called from the_content and friends) walks the rendered HTML, finds <img> tags, and injects loading="lazy" when the attribute is absent. Since 5.9, it also tracks an “is the first image” counter and skips the lazy attribute on that first image, on the theory that the first image is the LCP candidate. The theory works on simple layouts and fails on three common patterns: blocks rendered above the title (cover blocks), images inside template parts (the site header logo counts as the first image), and images injected by shortcodes that bypass the filter.

The result: on themes with a logo in the header, the logo gets the “no lazy” treatment and the hero image — the actual LCP — gets loading="lazy". LCP regresses, the editorial team has no idea why, and the Lighthouse report flags it.

How to verify

curl -s https://example.com/article-slug/ | grep -oE '<img[^>]+loading="[^"]+"[^>]*>' | head -5
curl -s https://example.com/article-slug/ | grep -oE '<img[^>]+>' | head -10

wp eval 'echo get_option("wp_omit_loading_attr_threshold") . PHP_EOL;'

npx lighthouse https://example.com/article-slug/ --only-categories=performance --quiet

Open the page in Chrome, DevTools > Performance > Insights tab. The “LCP” entry shows the LCP element. If it has loading="lazy", the heuristic failed for you.

The fix

  1. Use the fetchpriority="high" attribute on the hero image. Since WordPress 6.3, core sets fetchpriority="high" on the first content image. Confirm it lands on the right image; if the heuristic picks the wrong one, override with a filter.
  2. Filter wp_omit_loading_attr_threshold to control the first-image skip. Returning 0 disables the skip entirely (every image gets lazy). Returning 2 skips the first two images (useful when the logo counts as image one).
  3. Override per-template. For archive pages and homepages, the LCP is usually a specific block or featured image. Use the wp_get_loading_optimization_attributes filter to set fetchpriority="high" on that specific image and loading="eager" to prevent lazy.
  4. Strip lazy from images injected by plugins. Page builders (Elementor, Beaver Builder) sometimes add their own lazy-load on top of core’s. Two lazy attributes is one too many — pick one.
  5. Test with WebPageTest, not just Lighthouse. Lighthouse runs locally on a fast network. WebPageTest runs from a real mobile profile and catches LCP regressions Lighthouse misses. For sites under Enterprise WordPress management, Core Web Vitals checks run on a synthetic schedule and break the build when LCP regresses past threshold.

Stack Harbor’s Enterprise WordPress operating model includes Core Web Vitals monitoring with synthetic checks on the key templates, not just the homepage. When LCP keeps regressing on releases, start the conversation.