Disable LazyLoad on Mobile

In this article

Disabling LazyLoad When Mobile Caching is Active

Sometimes LazyLoad might work fine on desktop computers, but causes an issue on mobile devices.
When you have both Mobile Caching AND it's sub-option "Create a caching file for mobile visitors" enabled, you can use the below snippet in an MU Plugin to deactivate LazyLoad only on mobile. 

1

Create a folder named  mu-plugins in your wp-content folder.
If an mu-plugins folder already exists, don’t create a new one, just use the existing one.

2

Using a basic text editor  create a new file and put the following code in it:


<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
/**
 * Plugin Name: WP Rocket | UnLazyLoad Mobile
 * Description: Disables LazyLoad When Mobile Caching Active
 * Author:      WP Rocket Support Team
 * Author URI:  http://wp-rocket.me/
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

add_filter( 'wp', '__deactivate_rocket_lazyload_only_on_mobile' );
function __deactivate_rocket_lazyload_only_on_mobile() {
	if( class_exists( 'Rocket_Mobile_Detect' ) && get_rocket_option( 'do_caching_mobile_files', false ) ) {
		$detect = new Rocket_Mobile_Detect();
	
		if ( $detect->isMobile() && ! $detect->isTablet() ) {
			// Images
			add_filter( 'do_rocket_lazyload', '__return_false' );
			
			// Iframes
			add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
		}
	}
}
	
3
Save the file as wp-rocket-unlazyload-mobile.php
4
Upload this file to the mu-plugins folder created in step 1.
5
Finally, make sure to deactivate and re-activate WP Rocket.

Disabling LazyLoad On Mobile - Without Mobile Caching

If you have enabled LazyLoad, it will still be active on un-cached pages by default.

If you want to disable LazyLoad for mobile devices you can do the following:

1

Disable mobile caching in WP Rocket’s Basic Options.

2
Create a folder named mu-plugins in your wp-content folder.
In case a mu-plugins folder already exists, don’t create a new one, just use the existing one.
3

Using a basic text editor create a new file and put the following code in it:

<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
/**
 * Plugin Name: WP Rocket | UnLazyLoad Mobile
 * Description: Disables LazyLoad for mobile devices.
 * Author:      WP Rocket Support Team
 * Author URI:  http://wp-rocket.me/
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

if ( wp_is_mobile() ) {
	add_filter( 'do_rocket_lazyload', '__return_false' );
}
	
4
Save the file as wp-rocket-unlazyload-mobile.php
5
Upload this file to the mu-plugins folder created in step 1.
6
Finally, make sure to deactivate and re-activate WP Rocket.

Note: This will only work when mobile caching is disabled in step 1.