Archived topic
How to Prevent Lazy Loading Featured Images on Posts & Pages
4 replies · Started by MMS on September 10, 2021
Hi, I have the WP Rocket plugin and have been advised to improve LCP Core Web Vitals scores I need to disable lazy loading of featured images on posts/pages. Is it possible to do this on all posts/pages rather than having to use 'skip-lazy' on each individual post?
Hi,
This seems more of an WP Rocket question. But on the Media tab in WP Rocket you have a LazyLoad section. There is a Excluded images or iframes text area. This accepts filenames, CSS classes and domains. So you could place the CSS class that all the featured images have in common in there and, then the should be excluded from the WP Rocket LazyLoad.
Do bare in mind that this function only works from WP Rocket version 3.8+ If you use an older version I would recommend looking at this git repo from WP Rocket them self.
Hi there,
see this topic:
It will add the first-featured-image class directly to featured image <img> HTML that you can then add to the WP Rocket lazyload exclusions.
Or you can edit this line of the code:
$attr['class'] .= ' first-featured-image';
to add the skip-lazy class ie.
$attr['class'] .= ' skip-lazy';
It will also apply to the first post in your post archives, as that generally sits above the fold on mobile devices.
Thanks :)
You're welcome