Remove Width & Height from Image Inserted Using Media Uploader

When you insert an image from the media uploader the image code and url is inserted into the HTML are, the image code also contains width and height attribute.

If by any chance you don’t want to display the width & height attribute in the generated image code, this code will be useful. Put the codes in your functions.php

add_filter( 'post_thumbnail_html', 'delete_image_width_height', 20 );
add_filter( 'image_send_to_editor', 'delete_image_width_height', 20 );
 
function delete_image_width_height( $html ) {
   $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
   return $html;
}

Inspire us with your love!

Facebook Twitter Pinterest Reddit
Avatar

aThemeArt Editorial Staff prepares and cooks all the content that are published on athemeart.com. They are responsible for all type of web content including blog, social posts, videos, documentation etc.

You can check also

Leave a Reply

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

*
*