默認(rèn)情況下,通過WordPress自身的媒體上傳功能插入到文章的圖片,都會(huì)默認(rèn)添加了高度和寬度屬性:
<img title="使用 Chrome Workspace 進(jìn)行網(wǎng)站調(diào)試 | 倡萌的自留地 cmhello.com" alt="使用 Chrome Workspace 進(jìn)行網(wǎng)站調(diào)試" src="http://pic.cmhello.com/cmhello/Chrome-Workspace_9515/0019-cmhello_com.png" width="550" height="307" />
如果出于某些原因,你想去掉這個(gè)高度和寬度屬性,可以將下面的代碼添加到主題的 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;
}
參考資料:http://css-tricks.com/snippets/wordpress/remove-width-and-height-attributes-from-inserted-images/
聲明:本站所有文章,如無特殊說明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個(gè)人或組織,在未征得本站同意時(shí),禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。





已發(fā)布的文章怎么弄啊
這個(gè)只是在插入文章的時(shí)候去掉width和height,建議加上
add_filter( 'the_content', 'kite_remove_image_size_attr', 10 );add_filter( 'the_excerpt', 'kite_remove_image_size_attr', 10 );
可以去掉已經(jīng)發(fā)布了的文章里面的寬度和高度。
?? 你這個(gè)好像也不對吧,kite 和 attr 是什么?
?? 不知道為什么,我的wordpress4.01下無效啊。
沒想到什么實(shí)際用途
這個(gè)功能不錯(cuò) 尤其是想要弄自適應(yīng)主題的時(shí)候 上次我還是用JS操作的 有這個(gè)辦法就好了
max-width就行啊