Skip to content

Instantly share code, notes, and snippets.

@seojacky
Created November 13, 2021 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seojacky/c4988df5cf5e0c63ad2f17c2f71ea330 to your computer and use it in GitHub Desktop.
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
<?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