如何仅对某些特定的注册缩略图大小“$size”运行此筛选器?比如“大”、“中”。。。。
add_filter( \'wp_get_attachment_image_attributes\', \'wpse8170_add_lazyload_to_attachment_image\', 10, 2 );
function wpse8170_add_lazyload_to_attachment_image( $attr, $attachment ) {
$attr[\'data-original\'] = $attr[\'src\'];
$attr[\'src\'] = \'grey.gif\';
return $attr;
}
谢谢
最合适的回答,由SO网友:Rutwick Gangurde 整理而成
这是一个黑客,但我想它应该会起作用。。。
add_filter( \'wp_get_attachment_image_attributes\', \'wpse8170_add_lazyload_to_attachment_image\', 10, 2 );
function wpse8170_add_lazyload_to_attachment_image( $attr, $attachment ) {
//use your image size here with attachment
if($attr[\'class\'] == \'attachment-large\'){
//do your stuff
}
return $attr;
}