Adds loading="lazy" to img tags that have width and height attributes
- Since
- 5.5
- Detail from the docs
- Both dimension attributes must be present, to reduce layout shifting
WordPress adds loading="lazy" itself. See which images it covers, how it protects the LCP image with fetchpriority, and the filters to override it.
Since WordPress 5.5, core adds the native loading="lazy" attribute to images that have width and height attributes. Since 6.3 it also sets fetchpriority="high" on the image it judges most likely to be the LCP image, and never combines the two on one image. You only need to act when a hero image, or a theme template, gets the wrong attribute.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
srcset and sizes. The rules below come from the WordPress core dev notes for 5.5 and 6.3 and the developer reference for wp_get_loading_optimization_attributes().loading="lazy" to img tags that have width and height attributeswidth and height on images that lack themimg tag has the wp-image-$id classwp_get_attachment_image() outputthe_content, the_excerpt, widget_text_content, get_avatar and wp_get_attachment_imagefetchpriority="high" to the image most likely to be the LCP imageloading for early imagesdecoding="async" to imagesdecoding attributeloading="eager" does not load an image faster than one with no attribute. To raise priority, use fetchpriority="high".web.dev adds that an image with loading="lazy" and fetchpriority="high" is still delayed while it is off-screen, and that the combination isn't really necessary. WordPress core is built around the same rule, which is why it detects in-viewport images and drops the lazy attribute from them. Read more in lazy loading and lazy-loaded LCP image.
loading or fetchpriority before the function runs, WordPress keeps your value. Start with the narrowest tool.echo wp_get_attachment_image(
42,
'large',
false,
array( 'loading' => false ),
);function disable_template_image_lazy_loading( $default, $tag_name, $context ) {
if ( 'img' === $tag_name && 'wp_get_attachment_image' === $context ) {
return false;
}
return $default;
}
add_filter(
'wp_lazy_loading_enabled',
'disable_template_image_lazy_loading',
10,
3
);add_filter(
'wp_min_priority_img_pixels',
function( $size ) {
if ( is_this_the_url_with_the_image() ) {
return 200 * 200; // Images at least as big as 200x200
}
return $size;
}
);WordPress recommends passing false rather than "eager" to the wp_img_tag_add_loading_attr filter when you want to disable lazy loading for a content image, so the attribute is omitted altogether. For theme templates, the 5.5 dev note says an image in header.php that is very likely in the initial viewport should skip the loading attribute. The is_this_the_url_with_the_image() call in the size-threshold snippet is the dev note's own placeholder, so replace it with your own check.
WordPress only adds loading="lazy" when both width and height are present. Images pasted as raw HTML or output by a plugin without dimensions can be loaded eagerly, and web.dev says missing dimensions default to 0 by 0 pixels, which can make a gallery load everything at once.
Width and height are only added for attachments whose img tag has the wp-image-$id class.
The pre_wp_get_loading_optimization_attributes and wp_get_loading_optimization_attributes filters can alter or short-circuit the output, so a lazy-loading or optimization plugin may disagree with core.
With the 6.3 default threshold of 3, the first content media elements are not lazy-loaded. A hero image placed after several other images can still get loading="lazy".
The 5.5 dev note calls the native attribute a progressive enhancement, and web.dev says unsupported browsers see no negative effect.
Run curl -s https://example.com/ | grep -o '<img[^>]*>' and look at the first large image. It should have no loading="lazy", and should carry fetchpriority="high" if WordPress picked it as the LCP image.
A later image should have loading="lazy" plus width and height. If it has neither, the markup was likely not output through core.
In browser DevTools, open the Network tab, filter by Img, and reload without scrolling. Images far below the fold should not load until you scroll near them.
Test a post, the home page and an archive. Core counts images per response, so each template can pick a different first image.
3 questions people ask next, answered from the sources on this page.
Yes. Since 5.5 it adds loading="lazy" to img tags with width and height attributes, in post content, excerpts, text widgets, avatars and wp_get_attachment_image() output.
For wp_get_attachment_image(), pass array( 'loading' => false ) as the attributes. For content images, return false from the wp_img_tag_add_loading_attr filter so the attribute is omitted.
Since 6.3 it adds fetchpriority="high" to the image it determines is most likely the LCP image. By default an image must be at least 50,000 pixels in width times height to qualify.
Run the free audit, then approve the fixes. Every change can be undone.