WordPress移除文章图片的宽度和高度属性

默认情况下,通过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;

}



微信扫描下方的二维码阅读本文


论坛搭建_网站论坛制作_论坛开发建设_800元全包 » WordPress移除文章图片的宽度和高度属性

2023我们与您携手共赢,为您的企业形象保驾护航!

获取报价 了解我们