Last active
May 9, 2020 11:34
-
-
Save wpmudev-sls/2703ce6c6c300746dea19f5d05a2bb60 to your computer and use it in GitHub Desktop.
Fix can't not disable Lazyload on front page
This file contains 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 | |
/** | |
* Plugin Name: [Smush Pro] - Fix can't not disable Lazyload on front page | |
* Description: [Smush Pro] - Fix can't not disable Lazyload on front/home page - 1123654612516222 | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; } | |
add_action( 'plugins_loaded', 'wpmudev_smpro_fix_can_not_disable_lazyload_on_frontpage_func', 100 ); | |
function wpmudev_smpro_fix_can_not_disable_lazyload_on_frontpage_func() { | |
if( defined('WP_SMUSH_VERSION') && class_exists( 'Smush\Core\Settings' ) ){ | |
add_action( 'template_redirect', 'wpmudev_smpro_fix_can_not_disable_lazyload_on_frontpage' ); | |
function wpmudev_smpro_fix_can_not_disable_lazyload_on_frontpage(){ | |
$lazy_settings = Smush\Core\Settings::get_instance()->get_setting( WP_SMUSH_PREFIX . 'lazy_load' ); | |
if( is_page() && | |
( | |
( empty( $lazy_settings['include']['frontpage'] ) && is_front_page() ) | |
|| ( empty( $lazy_settings['include']['frontpage'] ) && is_home() ) | |
) | |
){ | |
add_filter( 'the_content', 'wpmudev_smpro_content_disable_lazyload', 1 ); | |
} | |
} | |
if( ! function_exists('wpmudev_smpro_content_disable_lazyload') ){ | |
function wpmudev_smpro_content_disable_lazyload( $content ){ | |
$content = '<p style="display:none!important" data-src="#"></p>'. $content; | |
return $content; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment