Copyright 2017-2020 All Rights Reserved Theme byKC模板网_织梦源码素材资源网站站长网下载分享类网站模板织梦源码资源站
皖ICP备15015255号-1
默认情况下,通过WordPress自身的媒体上传功能插入到文章的图片,都会默认添加了高度和宽度属性:
如果想去掉这个高度和宽度属性,可以将下面的代码添加到主题的 functions.php 文件即可:
add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 );
function remove_width_attribute( $html ) {
$html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
return $html;
}