Skip to content

Instantly share code, notes, and snippets.

@remyperona
Created January 31, 2017 20:31
Show Gist options
  • Save remyperona/b7ab7d0867b5921f8d6ed9c41527a8ec to your computer and use it in GitHub Desktop.
Save remyperona/b7ab7d0867b5921f8d6ed9c41527a8ec to your computer and use it in GitHub Desktop.
<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
/**
* Plugin Name: WP Rocket | LazyLoad Mobile
* Description: Enable LazyLoad only for mobile
* 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', 'rocket_enable_lazyload_only_on_mobile' );
function rocket_enable_lazyload_only_on_mobile() {
if( class_exists( 'Rocket_Mobile_Detect' ) && get_rocket_option( 'do_caching_mobile_files', false ) ) {
$detect = new Rocket_Mobile_Detect();
// Images
add_filter( 'do_rocket_lazyload', '__return_false' );
// Iframes
add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
if ( $detect->isMobile() && ! $detect->isTablet() ) {
// Images
add_filter( 'do_rocket_lazyload', '__return_true' );
// Iframes
add_filter( 'do_rocket_lazyload_iframes', '__return_true' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment