wordpress教程
WordPress移除文章图片的宽度和高度属性
wordpress教程
51源码
2022-11-11
共人阅读
默认情况下,通过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;
}
版权声明:文章搜集于网络,如有侵权请联系本站,转载请说明出处:https://www.51yma.cn/jiaocheng/wordpress/534.html
文章来源:
热门推荐
-
01WordPress引用加载PHP模板方法 859
-
02选WordPress主机空间看这3点 810
-
03利用宝塔面板优化WordPress缓存 808
-
04新手利用WordPress建站详细步骤分享 751
-
05WordPress只搜索标题 731