Exclude class from LazyLoad without adding it in Admin settings

I logged an issue a while ago about the fact that we can’t use the Smush UI to configure anything, because it crashes / times out (we have 500,000+ images so the query times out). I need to add a class exclusion though – how can I do this? Is there any way except adding the class in the Admin.

  • Adam
    • Support Gorilla

    Hello Bill

    I hope you’re well today and thank you for your question!

    Images can be excluded from lazy load without adding them via back-end in two ways:

    1) a “no-lazyload” class added to any image will automatically make Smush skip this image for Lazy Load.

    Note please:

    This will work

    <div>
    <img class="no-lazyload" src="someimage">
    </div> 
    

    but this won’t

    <div class="no-lazyload">
    <img srce="someimage">
    <div>

    Depending what images need to be excluded, it might be the simplest way – to add that class directly to images or e.g. in a related HTML of a relevant theme template file(s).

    2) there’s a filter for skipping images that can be used for this:

    apply_filters( 'smush_skip_image_from_lazy_load', false, $src, $image )

    This, however, doesn’t work based on the class but on specific images so it wold probably require some additional custom code to “list” these images and apply the filter to all of them.

    If you have any further questions, let me know, please.

    Kind regards,
    Adam