[WordPress教程] WordPress 删除特色图像CLASS或添加、删除某个CLASS样式名 -静鱼客栈

2021-09-29 0 719

一、完全去掉特色图像的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 

 

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

静鱼客栈 学习中心 [WordPress教程] WordPress 删除特色图像CLASS或添加、删除某个CLASS样式名 -静鱼客栈 https://wp.muooy.cn/9538.html

静鱼客栈的帅逼站长~

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务