Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bewho/6e1401ee8f278c38431f7689ed954400 to your computer and use it in GitHub Desktop.
Save bewho/6e1401ee8f278c38431f7689ed954400 to your computer and use it in GitHub Desktop.
[WordPress][WP Rocket] Programmatically disables WP Rocket’s LazyLoad feature on pages with Essential Grid.
<?php
/**
* Plugin Name: WP Rocket | UnLazyLoad Essential Grid
* Description: Disables WP Rocket’s LazyLoad feature on pages with <a href="https://www.themepunch.com/portfolio/essential-grid-wordpress-plugin/">Essential Grid</a>.
* Author: WP Rocket Support Team
* Author URI: http://wp-rocket.me/
* Plugin URI: http://docs.wp-rocket.me/article/139-disable-lazyload-on-mobile#inactive
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
defined( 'ABSPATH' ) or die( 'You know better.' );
/**
* Disables WP Rocket’s LazyLoad feature on pages with Essential Grid.
* @param string $content WP Post content
* @return string WP Post content
*/
function wp_rocket__unlazyload_essential_grid( $content ) {
if ( is_admin() || ! class_exists( 'Essential_Grid' ) || ! function_exists( 'has_shortcode' ) )
return $content;
if ( has_shortcode( $content, 'ess_grid' )
|| has_shortcode( $content, 'ess_grid_search' )
|| has_shortcode( $content, 'ess_grid_nav' )
|| has_shortcode( $content, 'ess_grid_ajax_target' ) ) {
add_filter( 'do_rocket_lazyload', '__return_false' );
}
return $content;
}
add_filter( 'the_content', 'wp_rocket__unlazyload_essential_grid' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment