Disabling LazyLoad on Specific Images

In this Article

Disable LazyLoad on an image

If you want to disable LazyLoad on a specific image, you can do so by adding the
data-no-lazy attribute to the img HTML tag:

<img src="my-image.jpg" data-no-lazy="1" alt="" width="100" width="100" />

Disabling LazyLoad on an image class

You can target a specific class to exclude from LazyLoad by using the following:

function rocket_lazyload_exclude_class( $attributes ) {
	$attributes[] = 'class="divi-slider"';

	return $attributes;
}
add_filter( 'rocket_lazyload_excluded_attributes', 'rocket_lazyload_exclude_class' );

In this example, the class name(s) assigned to $attributes must exactly match the HTML markup. If the actual class attribute is class="divi-slider something-else", the code above will not work.

The following example addresses images with more than one class name:

class="some-image-123 attachment-post-thumbnail size-post-thumbnail wp-post-image"

In that case, you can just remove the double quotes at the end, so the keyword for WP Rocket’s detection stays “open”:

$attributes[] = 'class="some-image-'; // 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, regardless of any additional class names they might have.

Disabling LazyLoad by image source

You can target an image by its src, allowing you to exclude images from LazyLoad that are hosted on other domain. In the below example, images served from wp.com will be excluded from LazyLoad:

function rocket_lazyload_exclude_src( $src ) {
	$src[] = 'wp.com';

	return $src;
}
add_filter( 'rocket_lazyload_excluded_src', 'rocket_lazyload_exclude_src' );

Disabling LazyLoad on avatars

If you want to disable Lazyload on your website's avatars, you can do so by adding this code to a custom plugin:

remove_filter( 'get_avatar', 'rocket_lazyload_images', PHP_INT_MAX );