WordPress: Remove width and height attributes of inserted images

888u

Last update at :2024-07-06,Edit by888u

When you upload an image through the WordPress media uploader and then insert it into the editor, it will have width and height attributes by default. If you want to remove the default width and height attributes, add the following code to your functions.php file.

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;
}

Recommended site searches: domain name valuation query, purchase of high-defense server, foreign server rental, Alibaba Cloud domain name registration, vps dynamic IP, US virtual host, virtual host, overseas host, public network IP, 100m virtual host,

p>

WordPress: Remove width and height attributes of inserted images

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码