Created
November 13, 2021 21:43
-
-
Save seojacky/c4988df5cf5e0c63ad2f17c2f71ea330 to your computer and use it in GitHub Desktop.
Disable Loading lazy for FIRST image in content & Disable Loading lazy for thumbnail
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 | |
//Disable Loading lazy for thumbnail | |
function disable_template_image_lazy_loading( $default, $tag_name, $context ) { | |
if ( 'img' === $tag_name && 'wp_get_attachment_image' === $context ) { | |
return false; | |
} | |
return $default; | |
} | |
add_filter( | |
'wp_lazy_loading_enabled', | |
'disable_template_image_lazy_loading', | |
99, | |
3 | |
); | |
//Disable Loading lazy for FIRST image in content | |
add_filter('the_content', 'the_end'); | |
function the_end( $post_content ){ | |
$pos = strpos($post_content, 'loading="lazy"'); | |
return $pos!==false ? substr_replace($post_content, '', $pos, strlen('loading="lazy"')) : $post_content; | |
//return $post_content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment