Support » Plugin: LazyLoad Plugin – Lazy Load Images, Videos, and Iframes » exclude the first X image(s) from the lazy loading

  • Resolved evil



    how can i exclude the first X image(s) from the lazy loading feature without having a specific class, which is not ideal considering WordPress gives all images the exact same class.

    This is extra important now that Google is putting extra emphasis with their new Web Vitals update and above-the-fold content.

    this is a major problem with the lazy loading plugins that Causes Largest Contentful Paint (LCP) issue

Viewing 1 replies (of 1 total)
  • Plugin Contributor WP Rocket


    Hi @p47ri0t!

    I’m afraid that this is not something that can be done for the time being.

    You will need to either target a class using the following filter:

    function rocket_lazyload_exclude_class( array $attributes ) {
    	// you can add as many classes as you want, one per line.
    	// IMPORTANT: The string match is literal, the string assigned to $attributes must exactly match the HTML markup.
    	$attributes[] = 'class="divi-slider"';  
    	//In above example, the class must be exactly class="divi-slider". If the actual class attribute is class="divi-slider something-else", the exclusion will not work.
    	$attributes[] = 'class="some-image-'; 	
    	// In the above example, note the missing double quotes at the end. This would exclude all images with a class of some-image-123, some-image-bla-bla, some-image-whatever-else etc. from being lazy-loaded, and it will also include cases where other classes are present: class="some-image-123 other-class and-other-one".
    	$attributes[] = 'specific-class-name'; 	
    	// You can also target one specific class name using only the name of the class. Any image using that class name will be excluded. it will cover cases like class="some-image-123 other-class specific-class-name and-other-one"
    	return $attributes;
    add_filter( 'rocket_lazyload_excluded_attributes', 'rocket_lazyload_exclude_class' );

    Or targeting a file name pattern using the following filter:

    function exclude_src( array $excluded_src ) {
    	$excluded_src[] = '';    // <img src="">
    	$excluded_src[] = '/example-path';  // <img src="/example-path/image.jpg">
    	$excluded_src[] = '/example?query'; // <img src="example?query=image.jpg">
    	return $excluded_src;
    add_filter( 'rocket_lazyload_excluded_src', 'exclude_src' );

    Best regards,


Viewing 1 replies (of 1 total)
  • The topic ‘exclude the first X image(s) from the lazy loading’ is closed to new replies.