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 remove loading=”lazy”. Therefore, WordPress default or native lazy loading will be disabled.
Let me know if this works for you.
Thank you very much. After a lot searching I found this article. This works for me. Really this is the working solution.
How can i disable lazy load for a specific image adding in elementor?
I don’t use Elementor. So, I don’t know. But if you use Litespeed cache plugin to lazy load images, there is a way. Add a class name to your specific image, then exclude it from Litespeed setting. Go to Page Optimization > Media Excludes. Add that class name in “Lazy Load Image Class Name Excludes” box.