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. frank Post author

      code snippets plugin indeed, but I’ll add it to the settings-page real soon (working on some small improvements for 2.8.1 now)

      Reply
  1. David

    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
    1. frank Post author

      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 Reply

Your email address will not be published. Required fields are marked *

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