通过 WordPress 后台上传图片,并且将图片插入到日志中,WordPress 会自动生成的 <img> 的 html 标签中包含图片的宽度和高度参数,如果你使用的是响应式的 WordPress 主题,那么这个可能会造成一些问题。下面的这段代码可以解决这个问题。
将下面代码复制到当前主题的 functions.php
文件中:
//删除WordPress文章图片的宽度和高度参数 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; }
至此,本文结束。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END