取消WordPress Gallery預設輸出圖片width和height

WordPress Gallery 藝廊功能,預設輸出時會透過img語法內的width和height的屬性來鎖定圖片大小,但是如果版面要調整這樣可能會很麻煩,因此我們可以透過function來做一個去除動作,接著我們可以利用CSS去設定新的高寬,方便整體版面的排版。

取消WordPress Gallery 預設高(height)、寬(width)

修改佈景主題:functions.php

function remove_img_width_height($html) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}
add_filter('wp_get_attachment_link', 'remove_img_width_height', 10, 1);