I try to set lazyload for videos and iframes inside functions.php
How to manage videos and iframes?
Need help.
<?php
function wp_lazy_loading_enabled( $tag_name, $context ) {
$default = ( 'img' === $tag_name );
return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );
}
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',
10,
3
);
function skip_loading_lazy_image_42_large( $value, $image, $context ) {
if ( 'the_content' === $context ) {
$image_url = wp_get_attachment_image_url( 42, 'large' );
if ( false !== strpos( $image, ' src="' . $image_url . '"' ) {
return false;
}
}
return $value;
}
add_filter(
'wp_img_tag_add_loading_attr',
'skip_loading_lazy_image_42_large',
10,
3
);
?>