I have a callback applied to wp_get_attachment_image_attributes
to add attributes to the generated image html.
function add_lazyload_to_attachment_image($attr, $attachment)
{
if (strpos($attr['class'], 'lazyload') !== false) {
$attr['data-src'] = $attr['src'];
if (isset($attr['srcset'])) {
$attr['data-srcset'] = $attr['srcset'];
$attr['data-sizes'] = "auto";
$attr['srcset'] = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
}
}
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'add_lazyload_to_attachment_image', 30, 2);
But the function does not get applied some custom image sizes. This filter works for the default image sizes present in Wordpress.
I want this filter to work for all custom image sizes. Please help.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745625357a4636770.html
评论列表(0条)