一、完全去掉特色图像的CLASS或者其他属性
将下面代码添加至functions.php文件任意位置即可。如果想去掉其他属性,例如alt,将下面代码里的$attr[‘class’]
替换成$attr[‘alt’]
function uazoh_remove_wp_post_image( $attr ) {
unset($attr['class']);
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'uazoh_remove_wp_post_image', 20 );
二、添加新的class
例如想添加一个uazoh_attr,将下面代码添加至functions.php文件任意位置即可。注意,要添加的class前面要带一个空格。
function uazoh_remove_wp_post_image( $attr ) {
$attr['class'] .= ' uazoh_attr';
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'uazoh_remove_wp_post_image', 20 );
三、清空CLASS,但保留CLASS属性标致
这个也许不会有人需要……不过奇葩年年有嘛……将下面代码添加至functions.php文件任意位置:
function uazoh_remove_wp_post_image( $attr ) {
$attr['class'] = ' ';
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'uazoh_remove_wp_post_image', 20