Last active
July 20, 2024 14:27
-
-
Save ianpegg/41fb0d5df8cb55f648b42e176b152012 to your computer and use it in GitHub Desktop.
PHP MU plugin include that disables image and iframe lazy loading included in WordPress core since 5.4. There is no need to use this unless you know you need it!
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 | |
| /** | |
| * Plugin Name: eggMUP: Disable Browser Lazyloading | |
| * Plugin URI: https://gist.github.com/ianpegg/41fb0d5df8cb55f648b42e176b152012 | |
| * Description: Browser-based lazyloading is great, but not yet fully supported. If you are using a JS lazy loading solution, you don't need both. This must-use plugin disables browser lazy loading that was added in WP 5.4. | |
| * Version: 1.0.0 | |
| * Author: Ian Pegg | |
| * Author URI: https://eggcupwebdesign.com | |
| * php version 7.4.15 | |
| * | |
| * @category Must_Use_Plugin | |
| * @package WordPress_Plugin | |
| * @author Ian Pegg <hello@eggcupweb.com> | |
| * @license GNU/GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
| * @link https://eggcupwebdesign.com | |
| */ | |
| namespace EggCup\MUP\DisableCoreLazyLoading; | |
| if (!defined('ABSPATH')) { | |
| exit; | |
| } | |
| /** | |
| * Register the following functions with WP action hooks/filters: | |
| */ | |
| add_filter( | |
| 'wp_lazy_loading_enabled', | |
| __NAMESPACE__ . '\\Disable_Core_Lazy_loading', | |
| 10, | |
| 3 | |
| ); | |
| /** | |
| * Disables WP core lazy loading of iframes and images as | |
| * LiteSpeed's implementation is more effective - for now... | |
| * | |
| * @param Bool $Bool_default Whether lazy loading is enabled by default | |
| * @param String $Str_tag_name Current HTML tag: img or iframe | |
| * @param String $Str_context Current context, e.g. body content, widget | |
| * | |
| * @return void | |
| */ | |
| function Disable_Core_Lazy_loading($Bool_default, $Str_tag_name, $Str_context) | |
| { | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment