How to Set Up Lazy Loading for Images on WordPress Without Breaking Your Layout

How to Set Up Lazy Loading for Images on WordPress Without Breaking Your Layout

If your WordPress site loads dozens of product photos, blog images, or gallery thumbnails, every one of those files has to download before a visitor can see the page fully. Lazy loading solves this by deferring images that sit below the visible area until a reader scrolls toward them. The idea is simple, but the setup can go wrong quickly. Images collapse into blank boxes, sliders break, or the page jumps around as files arrive. This guide explains how lazy loading works in WordPress, how to enable it safely, and how to avoid the layout problems that frustrate site owners and visitors alike.

What Lazy Loading Actually Does

Lazy loading tells the browser to hold off on downloading an image until it is close to entering the viewport. Images that appear in the first screen of content, often called above-the-fold images, are usually loaded immediately, because the visitor needs them right away. Everything further down the page can wait.

Modern browsers support this natively through the loading attribute on <img> tags. Setting loading="lazy" asks the browser to defer the image, and loading="eager" asks it to fetch the image straight away. You can read the current browser behaviour and support details in the MDN documentation on the lazy loading guide.

WordPress has supported the native attribute since version 5.5, which means many sites already lazy load images without any plugin. Whether you rely on that default or add extra functionality, the main goal is the same: reduce the amount of data a visitor downloads before the page feels usable, without making the page look broken while it loads.

Why Layouts Break When Lazy Loading Goes Wrong

Most layout problems come from one root cause. The browser does not know how tall or wide an image will be until the file arrives. If the page reserves no space for the image, the text below it shifts downward once the picture loads. This is called layout shift, and it hurts both user experience and Core Web Vitals scores, specifically the Cumulative Layout Shift metric described in Google's Cumulative Layout Shift documentation.

Other common causes include:

  • Images without declared width and height attributes, so the browser cannot calculate space in advance.
  • CSS rules that set a height to auto on containers that also contain lazy images.
  • Theme sliders or carousels that measure the width of hidden slides before the images inside them have loaded.
  • Plugins that replace the image source with a placeholder but do not preserve the original dimensions.
  • Lazy loading applied to logos or hero images that should load immediately, which makes the top of the page appear empty.

Understanding these causes makes the setup process easier, because most fixes involve giving the browser the information it needs before the image arrives.

Step 1: Check What WordPress Is Already Doing

Before changing anything, find out whether lazy loading is already active. Open a page on your site, right-click an image that sits further down, and choose View Page Source. Search for loading="lazy". If you see it on images, native lazy loading is working. If you see no attribute at all, either the feature has been disabled by a theme or plugin, or the images were added in a way WordPress does not process.

Also check your theme. Some themes add their own lazy loading script that conflicts with the native attribute, which can result in images appearing twice or not appearing at all. If you find two lazy loading systems, disable one of them before adding a third.

Step 2: Use Native Lazy Loading Where Possible

For most sites, the built-in WordPress behaviour is the safest starting point. WordPress adds loading="lazy" to images in post content automatically, and it skips the first image in many contexts so the visible portion of the page is not delayed. You do not need to write code to benefit from it.

If you want to confirm or control this behaviour, WordPress exposes a filter called wp_lazyload_images and the wp_img_tag_add_loading_attr filter in the developer reference. These filters let a developer decide which images receive the attribute. Only use them if you are comfortable editing your theme's functions file or a site-specific plugin, and always test on a staging copy first.

Step 3: Declare Image Dimensions

This is the single most effective fix for layout shift. When an image has explicit width and height attributes, the browser calculates the aspect ratio and reserves the correct space before the file downloads. WordPress usually adds these attributes when you insert an image from the Media Library, but they can be lost when images are pasted as raw HTML, when content is imported from another site, or when a page builder outputs its own markup.

To check, look at the image tag in the source. It should include something like width="800" height=600. If those attributes are missing, re-insert the image from the Media Library or add the attributes manually. Responsive CSS can still scale the image down; the attributes simply tell the browser the original proportions.

For theme-generated images such as featured images, make sure your template passes the dimensions through. Most modern themes handle this, but custom templates sometimes do not.

Step 4: Keep Above-the-Fold Images Eager

The logo, the main hero banner, and the first featured image on a page should almost always load immediately. If they are lazy loaded, visitors may see empty space at the top of the page, which feels like a broken site even though the rest of the content is fine.

You can set the loading attribute explicitly on these images. In the block editor, select the image block, open the Advanced panel in the sidebar if your version provides it, and check the loading option where available. In a theme template, you can hard-code loading="eager" on the hero image and fetchpriority="high" if it is the largest element in the first view. Keep the number of eager images small, because loading too many at once reduces the benefit of the whole exercise.

Step 5: Handle Sliders, Galleries, and Tabs Carefully

Sliders and galleries are a common source of breakage. A slider may calculate its height using the first slide, then struggle when later slides load late. Tabs and accordions can hide images with display: none, and some browsers and scripts do not trigger lazy loading correctly for hidden content.

When you run into this, try the following approach:

  1. Disable lazy loading for images inside the slider and enable it for the rest of the page. Many slider plugins have their own setting for this.
  2. Give the slider container a fixed aspect ratio using CSS, so it reserves its height regardless of image loading.
  3. Test the slider on a mobile device and on a slow connection. Browser developer tools let you throttle network speed, which quickly reveals timing problems.