使用wordpress編輯器上傳圖片都會自動給圖片增加寬度和高度,有時我們不希望有這相屬性,下面我來給各位同學介紹移除WordPress文章圖片的寬度和高度屬性的方法.
如我個上傳時會自動加屬性,代碼如下:
- <img title="使用 Chrome Workspace 進行網站調試 | 倡萌的自留地 cmhello.com" alt="使用 Chrome Workspace 進行網站調試" src="/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;
- }
新聞熱點
疑難解答
圖片精選