apply_filters ( 'jetpack_lazy_images_blacklisted_classes', array An )

Allow plugins and themes to tell lazy images to skip an image with a given class.

Source file: modules/lazy-images/lazy-images.php

View in GitHub

Parameters

An

(array) An array of strings where each string is a class.


Changelog

Since: Jetpack 5.9.0


Notes

Have a note to contribute?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Comments

  1. Rodolfo says:

    Here’s a quick example to exclude your logo (given the logo’s class “custom-logo”) from lazy loading:

    
    add_filter( 'jetpack_lazy_images_blacklisted_classes', 'bbloomer_exclude_custom_logo_class_from_lazy_load', 999, 1 );
                   
    function bbloomer_exclude_custom_logo_class_from_lazy_load( $classes ) {
        $classes[] = 'custom-logo';
        return $classes;
    }   
    
    
    • mygoldenthimble says:

      How about if I want to exclude all woocomerce pictures??? But still lazy load anywhere else on my site?

    • Erez Speiser says:

      Thanks to that code snippet. It was most helpful!. Can you share what is the syntax if I want to exclude more than one class? Thanks

      • Jeremy says:

        Hi there,

        One way to exclude multiple classes would be to adjust the above example like so:

        function bbloomer_exclude_custom_logo_class_from_lazy_load( $classes ) {
          $classes[] = 'custom-logo';
          $classes[] = 'second-class';
          $classes[] = 'third-class';
          return $classes;
        }
        

        Best!

  2. Loayon Lou says:

    Hi! This works but still it adds noscript tag which gives w3c error when I’m using picture tag http://prntscr.com/pb6oys. How will I fix it?

    • Jeremy Herve says:

      It’s currently not possible to remove those noscript tags. We’re tracking this issue here. I would recommend that you subscribe to the issue to follow our progress on this.

  3. Sandra says:

    I really need help creating a snippet for turning off Lazy Images only on the homepage.