Disable LazyLoad on specific posts

If you want to disable LazyLoad on a specific post or page, you can do so directly on the Edit screen using the WP Rocket Options meta box. Uncheck the LazyLoad option and publish or update the post.

Disable LazyLoad programmatically

You can programmatically disable LazyLoad on specific posts or pages utilizing a WordPress filter. Use the following helper plugin as a boilerplate, and edit the code to fit your specific use case:

📥  Download (.zip):  WP Rocket | No LazyLoad
Developers: You can find the code for this plugin on GitHub.

Heads up! You must delete the functions you don’t need before running this plugin, otherwise LazyLoad will be deactivated on single post pages, product pages, and search result pages.

Below are a couple of examples on how to come up with your own function.

Disable LazyLoad on all pages

function deactivate_on_page() {
	if ( is_page() ) {
		add_filter( 'do_rocket_lazyload', '__return_false' );
	}
}
add_filter( 'wp', __NAMESPACE__ . '\deactivate_on_page' );

Disable LazyLoad on front page

The front page of your site is the one set in Settings â†’ Reading â†’ Front page displays. It can be an actual page, or an archive page with your latest blog posts.

function deactivate_on_front_page() {
	if ( is_front_page() ) {
		add_filter( 'do_rocket_lazyload', '__return_false' );
	}
}
add_filter( 'wp', __NAMESPACE__ . '\deactivate_on_front_page' );

Disable LazyLoad on blog page

The blog page of your site is the one displaying an archive of your recent posts. It can be the front page, or any other page you have set to display such archive in Settings â†’ Reading â†’ Front page displays.

function deactivate_on_blog_page() {
	if ( is_home() ) {
		add_filter( 'do_rocket_lazyload', '__return_false' );
	}
}
add_filter( 'wp', __NAMESPACE__ . '\deactivate_on_blog_page' );

Disable LazyLoad on single posts

A Single Post is the page you see when you open the permalink of a post. The required function is included in the plugin.

Disable LazyLoad on WooCommerce product pages

A Product Page in WooCommerce is the page you see when you open the permalink of a single product. The required function is included in the plugin.

Note: As you can see, only one line of code changes in the above samples. The functions used in those lines are called Conditional Tags. To learn more about Conditional Tags in WordPress, check out the official Theme Handbook:
Conditional Tags

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.