Lazy Load Images in WordPress Without a Plugin

A slow page loses visitors before they ever read your content. Images are often the heaviest part of a page, and when a page loads every image at once, the browser has to download far more than the visitor can see. Lazy loading fixes that waste by loading each image only when the visitor scrolls near it.
Here is the honest starting point: WordPress has lazy loaded images natively since version 5.5, through the loading=”lazy” attribute. Most images you add through the editor or the Media Library already lazy load without any plugin and without any extra code. This guide explains what core already does, what it does not cover, and the no plugin code methods for the gaps.
What Is Lazy Loading and Why Does It Help?
Lazy loading is a simple idea. The browser loads the images at the top of the page first, and it waits to load the images further down until the visitor scrolls close to them. An image below the fold is not downloaded on the first load at all, so the page needs fewer requests and less data.
The benefit shows up in the numbers that matter for speed. The first content appears sooner, and the total page weight drops on long pages with many images. Google documents the value of lazy loading for images at developers.google.com. Lazy loading alone will not fix a slow site, but on an image heavy page it is one of the easiest wins.
Before you change any code, fix the images themselves first. A lazy loaded image that is far too large is still a large download when the visitor reaches it. Our guide on WordPress image optimization without a plugin covers compression and sizing in detail.
Does WordPress Already Lazy Load Images by Default?
Yes, and this is the fact most tutorials skip. Since WordPress 5.5, released in August 2020, WordPress adds loading=”lazy” to images in post content automatically. When you insert an image into a post or a page through the block editor, WordPress outputs that attribute for you, and modern browsers respect it.
That native behaviour works because the loading attribute is a browser feature, not a WordPress feature alone. When the browser sees loading=”lazy” on an image, it waits until the image is near the viewport before it downloads the file. No JavaScript library is needed, and no extra plugin is needed for those standard images.
You can check this in a few seconds. Open any post on your site, right click an image below the first screen, and choose Inspect in your browser. If you see loading=”lazy” in the tag, WordPress core is already doing the job for that image. The official documentation at wordpress.org confirms the current WordPress version and its features.
What Does WordPress Core Lazy Loading Not Cover?
Native lazy loading is good, but it is not complete. WordPress adds the attribute to images that pass through its standard image functions, yet many images on a real site never pass through those functions. A logo, a banner, or a custom image hard coded into a theme template with a plain img tag will not get loading=”lazy” unless the theme developer added it by hand.
- Theme template images: hard coded img tags in header, footer, or custom templates that skip WordPress image functions.
- Background images: CSS background images never get a loading attribute, because they are not img tags at all.
- Custom HTML blocks: images pasted as raw HTML in the editor do not pass through the WordPress image filters.
- Some iframes: WordPress adds lazy loading to many iframes, but older embeds and custom iframe markup may miss it.
- Images above the fold: WordPress tries to keep the first image eager, but custom templates can still lazy load it by mistake.
Background images deserve a special note, because no loading attribute can fix them. A CSS background image loads when the browser parses the stylesheet rule, and lazy loading simply does not apply to it. For other speed problems that lazy loading cannot fix, read our guide on why your WordPress site is slow.
Why Must You Never Lazy Load the Hero Image?
The hero image is the large image at the top of the page, and it is usually the largest contentful paint element, which Google uses to judge how fast the visible page loads. If you lazy load that image, the browser waits before it downloads the most important visual on the page, and the page looks empty for longer.
WordPress tries to keep the first content image eager by default, and adds loading=”lazy” to later images. That logic only works for images WordPress controls, so always check the hero image after any change.
The rule is simple: never lazy load the hero image, the logo, or any image that appears in the first screen on a phone or a desktop. Lazy load only the images a visitor must scroll to reach. Test on a phone screen as well as a desktop screen, because the first screen is much shorter on a phone.
How Do You Add loading=”lazy” in a Theme Template?
When a theme template outputs an image with a plain img tag, you can add the loading attribute directly to that tag. This is the cleanest method for template images, because the change lives exactly where the image lives. Add loading=”lazy” to images below the fold, and leave loading=”eager” on the hero image and the logo.
<img src="https://yoursite.com/wp-content/uploads/team-photo.jpg" alt="Our team at work" width="800" height="600" loading="lazy" />
<img src="https://yoursite.com/wp-content/uploads/hero-banner.jpg" alt="Welcome to our site" width="1600" height="900" loading="eager" />
Always include width and height attributes on your images, because they reserve the right amount of space before the image loads. Without those attributes, the page layout shifts when a lazy image finally appears. Edit theme templates only in a child theme, never in a parent theme, because a theme update overwrites parent theme files.
How Do the wp_lazy_loading_enabled and wp_img_tag_add_loading_attr Filters Work?
WordPress provides two filters that control lazy loading from code. The wp_lazy_loading_enabled filter turns lazy loading on or off for a given context, such as images or iframes. The wp_img_tag_add_loading_attr filter lets you change the loading attribute on a specific image tag before WordPress outputs it.
function vtg_lazy_load_all_images( $default, $tag_name, $context ) {
if ( 'img' === $tag_name ) {
return true;
}
return $default;
}
add_filter( 'wp_lazy_loading_enabled', 'vtg_lazy_load_all_images', 10, 3 );
The example above keeps lazy loading enabled for images, which is already the default. Use the second filter, wp_img_tag_add_loading_attr, to change the attribute for a specific image, for example to force an image to stay eager. Add both filters to a child theme functions.php file or to the Code Snippets plugin.
Do not use these filters to lazy load every image without an exception for the hero image. A filter that applies to all images will also catch the first image, unless you add a condition that skips it.
How Do You Exclude Specific Images From Lazy Loading?
Some images must load immediately, even when they sit further down the page in the HTML. The hero image is the obvious case, but the same applies to a logo in a sticky header or a product image that appears the moment a visitor opens a page. WordPress supports a simple exclusion: add the class name skip-lazy to the image, and the lazy loading filters will leave it alone.
function vtg_skip_lazy_for_class( $value, $image, $context ) {
if ( false !== strpos( $image, 'skip-lazy' ) ) {
return false;
}
return $value;
}
add_filter( 'wp_img_tag_add_loading_attr', 'vtg_skip_lazy_for_class', 10, 3 );
In the block editor, add the class from the block settings panel, under the Advanced section, in the Additional CSS Class field. Type skip-lazy there, save the post, and that image will load eagerly. In a theme template, add class=”skip-lazy” to the img tag directly. If the image still shows loading=”lazy”, clear your caching plugin cache and check again.
How Do You Lazy Load Iframes Without a Plugin?
Iframes deserve the same treatment as images, because an embedded video or map can be one of the heaviest parts of a page. A YouTube embed loads scripts, styles, and a preview image before the visitor ever presses play. Lazy loading an iframe tells the browser to wait until the embed scrolls near the viewport.
WordPress adds loading=”lazy” to many iframes automatically, including standard video embeds, but custom iframe markup can miss it. You can add the attribute by hand to any iframe you paste into a custom HTML block or a template. The example below shows a YouTube embed with lazy loading enabled.
<iframe src="https://www.youtube.com/embed/VIDEO_ID" width="560" height="315" loading="lazy" title="Video tutorial"></iframe>
For video embeds, an even better option is a facade: a lightweight preview image that only loads the real video player when the visitor clicks it. That method saves far more data than lazy loading alone. For speed help beyond embeds, our guide on how to enable Gzip compression in WordPress without a plugin covers another easy server level win.
How Do You Test That Lazy Loading Works?
Testing is quick, and you should do it after every change. Open a long post, open your browser developer tools, and switch to the Network tab. Filter the view to images, then reload the page. You should see only the images near the top load at first, with the rest appearing as you scroll down.
- Inspect the image tag: confirm loading=”lazy” is present on below fold images.
- Check the hero image: confirm it loads eagerly and has no lazy attribute.
- Watch the Network tab: confirm below fold images load only when you scroll near them.
- Test on a phone: confirm the first screen still shows its images immediately.
- Run a speed test: compare the before and after results on the same page and connection.
Run a speed test with a tool such as PageSpeed Insights, and read the guidance at web.dev to understand what each score means. Compare the same page before and after your change, on the same connection. Clear every cache before each test, or the old page will keep appearing in the results.
What Mistakes Should You Avoid?
- Lazy loading the hero image, which delays the largest contentful paint and hurts the speed score.
- Installing a lazy loading plugin when WordPress core already lazy loads your content images.
- Forgetting width and height attributes, which causes layout shift when lazy images appear.
- Lazy loading every image with a blanket filter and no exclusion for the first image.
- Expecting lazy loading to fix background images, which never use a loading attribute.
- Testing without clearing the cache, and then judging the result from an old cached page.
The biggest mistake is the mindset behind the plugin search itself. Many site owners assume they need a plugin, because older tutorials were written before WordPress 5.5 added lazy loading to core. Today, check what core already does first, fix the gaps with the code methods in this guide, and protect the hero image.
Frequently Asked Questions
Does WordPress lazy load images without a plugin?
Yes. Since WordPress 5.5, WordPress adds loading=”lazy” to images in post content automatically, and modern browsers respect that attribute. Most images you add through the block editor or the Media Library already lazy load.
Should I lazy load the hero image on my homepage?
No. Never lazy load the hero image, because it is usually the largest contentful paint element. Lazy loading it delays the most important visual on the page and makes the speed score worse. Keep the hero image eager.
How do I stop WordPress from lazy loading a specific image?
Add the class skip-lazy to the image, either through the Additional CSS Class field in the block editor or directly in the img tag in a template. You can also use the wp_img_tag_add_loading_attr filter to return false for images that carry that class.
Does lazy loading work for iframes and videos too?
Yes. WordPress adds loading=”lazy” to many iframes automatically, and you can add the same attribute by hand to a custom iframe in a template or a custom HTML block. For YouTube embeds, a click to load facade saves even more data.
Last updated: November 2026.



