[Resolved] How to Prevent Lazy Loading Featured Images on Posts & Pages

Home Forums Support [Resolved] How to Prevent Lazy Loading Featured Images on Posts & Pages

Home Forums Support How to Prevent Lazy Loading Featured Images on Posts & Pages

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1925438
    MMS

    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?

    #1925448
    Elham

    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.

    #1925480
    David
    Staff
    Customer Support

    Hi there,

    see this topic:

    https://generatepress.com/forums/topic/add-a-class-to-the-featured-image-of-all-the-single-posts-on-my-site/#post-1816115

    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.

    #1925537
    MMS

    Thanks 🙂

    #1925554
    David
    Staff
    Customer Support

    You’re welcome

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.