把下面的代码放在functions.php中即可去掉img中的width和height属性,从而可以在css中自定义图片宽高。
PS:由于External Media without Import插件虽然可以使得外链图片插入在文章以及特色图像中使用,但是WordPress并无法使用外链图片进行缩略图功能,导致特色图像如果要使用外链就“参差不齐”,尚未没找到合适的解决办法,暂且用这个去掉特色图像长宽限制。
所谓的TimThumb——超好用的 PHP 略缩图裁剪插件,我直接就没搞懂是在干嘛。
1 2 3 4 5 6 7 8 |
// 自适应图片删除width和height 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; } |