Created
January 31, 2017 20:31
-
-
Save remyperona/b7ab7d0867b5921f8d6ed9c41527a8ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined( 'ABSPATH' ) or die( 'Cheatin’ 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