Lazy Load

How to Disable WordPress Native Lazy Loading (Working Solution)

WordPress 5.5 included lazy loading. WordPress now adds an attribute to all your images loading="lazy" to ensure they lazy load. Before that, many of us have already been using lazy loading by using a plugin like LiteSpeed Cache.

Now, to obtain a better Core Web Vital Score, you may want to disable lazy loading for certain images. Largest Contentful Paint (LCP) is one of the three Core Web Vitals metrics, and it represents how quickly the main content of a web page is loaded. Specifically, LCP measures the time from when the user initiates loading the page until the largest image or text block is rendered within the viewport.

Without disabling lazy loading for the largest image within the viewport, you can’t achieve a better score.

If you search for how to disable WordPress default lazy loading, you’ll get a solution that used to work but isn’t working anymore. That solution is related to wp_lazy_loading_enabled filter. This doesn’t work anymore, maybe from after WordPress 5.9. Here is the solution that works:

How to Disable WordPress Default Lazy Load Without Plugin

Paste following code to your theme’s functions.php file:

function disable_lazy_load_featured_images($attr, $attachment = null) {
	unset( $attr['loading'] );
	return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'disable_lazy_load_featured_images');

This will change remove loading=”lazy”. Therefore, WordPress default or native lazy loading will be disabled.

Let me know if this works for you.

Spread the love

A teacher by profession, a traveler by passion and a netizen by choice.

Morshed Alam

You use WordPress! Why don't we share our experience! It may be a tutorial, tips, tricks or about security, performance or WordPress news. Write Today

Leave a Comment

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