Created
March 17, 2022 19:54
-
-
Save zackkatz/eb33aa3de635a5716650c59757ee9232 to your computer and use it in GitHub Desktop.
GravityView - Disable lazy loading for images
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 | |
/** | |
* Disable lazy loading for images in GravityView (added in 2.14.3). | |
* | |
* @param string|bool $value The `loading` attribute value. Returning a falsey value will result in | |
* the attribute being omitted for the image. | |
* @param string $image The HTML `img` tag to be filtered. | |
* @param string $context Additional context about how the function was called or where the img tag is. | |
*/ | |
*/ | |
add_filter( 'wp_img_tag_add_loading_attr', function ( $value, $image, $context ) { | |
// This is not a GravityView image; don't modify lazy loading behavior. | |
if ( 'gravityview-image' !== $context ) { | |
return $value; | |
} | |
return false; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment