Home » Tutorial » How to Disable WordPress Native Lazy Loading (Working Solution)

How to Disable WordPress Native Lazy Loading (Working Solution)

Lazy Load

WordPress 5.5 includes lazy loading. WordPress now adds an attribute to all your images loading="lazy" to ensure they lazy load. Before that, many of us had 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 find 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 after WordPress 5.9. Here is the solution that works:

How to Disable WordPress Default Lazy Load Without Plugin

Paste the following code into 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 remove loading=”lazy”. Therefore, WordPress default or native lazy loading will be disabled.

Let me know if this works for you.

Read more from Tutorial

Written by:

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

Have you written on ThoughtMight?Write Today



Leave a Comment

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