attachments - Filter not applied to all image sizes

I have a callback applied to wp_get_attachment_image_attributes to add attributes to the generated image html.function a

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

相关推荐

  • attachments - Filter not applied to all image sizes

    I have a callback applied to wp_get_attachment_image_attributes to add attributes to the generated image html.function a

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信