近来因为某些缘由,给他人解答了几个关于WP的问题,因为问问题的人是一个完完整全的童贞座(上升星座也是童贞90%),所以迥殊抠细节。看到特征图象的wp-post-image以及其他地方都很不爽,愿望去掉……
在百度、GOOGLE上搜刮了一圈无果……发明原来就他有这个强迫症,网上基础没有人会愿望处理这个问题……
所以没办法……帮他写的代码……而这个代码有扩大用法……就一同编辑出来吧。
一、完整去掉特征图象的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 );

评论列表