About that new autoptimize_filter_imgopt_lazyload_from_nth filter

Some people asked for documentation/ information on that new autoptimize_filter_imgopt_lazyload_from_nth filter which allows one to tell AO not to optimize the first X images found in the HTML, so here is an example code snippet that sees AO not lazyload the first 5 images:
add_filter( 'autoptimize_filter_imgopt_lazyload_from_nth', function(){ return 5; } );
Update: as from AO 2.8.2 this will also be an option on the settings page, see screenshot 🙂
 

6 thoughts on “About that new autoptimize_filter_imgopt_lazyload_from_nth filter”

  1. Hi Frank,
    First of all, thanks so much for your great plugin.
    When is it recommended to use this functionality?
    Could you give an example of usage?
    Thank you

    Reply
    • Well, lazyload is great for images that are not visible yet, but ideally your above-the-fold images are not lazyloaded to avoid users having to wait long(er) on the image appearing. Telling AO not to lazyload the first X images found in the HTML (using the filter or now with AO 2.8.1 released the option on the images settings page) is meant to help doing just that; not lazyloading important images.

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.