How to Remove Height and Width From Inserted Images

When we upload an image with the help of WordPress media uploader and insert it into editor, it comes with height and width attributes. These are normally default attributes, as it assists browser to make appropriate room for the image during layout.

But if you want to remove these attributes from image then you can use below code

Just need to put this code in your theme functions.php file

add_filter( 'post_thumbnail_html', 'remove_image_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_image_attribute', 10 );

function remove_image_attribute( $html ) {
   $html = preg_replace( '/(height|width)="\d*"\s/', "", $html );
   return $html;

Leave a Reply

Your email address will not be published. Required fields are marked *