默认情况下,通过WordPress自身的媒体上传功能插入到文章的图片,都会默认添加了高度和宽度属性:
<img title="使用 Chrome Workspace 进行网站调试 | 倡萌的自留地 cmhello.com" alt="使用 Chrome Workspace 进行网站调试" src="http://pic.cmhello.com/cmhello/Chrome-Workspace_9515/0019-cmhello_com.png" width="550" height="307" /> |
<img title="使用 Chrome Workspace 进行网站调试 | 倡萌的自留地 cmhello.com" alt="使用 Chrome Workspace 进行网站调试" src="http://pic.cmhello.com/cmhello/Chrome-Workspace_9515/0019-cmhello_com.png" width="550" height="307" />
如果出于某些原因,你想去掉这个高度和宽度属性,可以将下面的代码添加到主题的 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;
} |
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;
}
参考资料:http://css-tricks.com/snippets/wordpress/remove-width-and-height-attributes-from-inserted-images/
来源:
https://www.wpdaxue.com/remove-width-and-height-attributes-from-inserted-images.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32782.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57