Remove Width & Height Attributes From Uploaded Images


If you upload images via the WordPress media uploader and insert it into your post, it will automatically include the image width and height attribute in the html <img> tag. These are normally desirable, as it assists the browser in making the appropriate room for the image during layout.

But for some reason if you want to get rid of these attributes from <img> tag in html, you can add this code to you functions.php file.

// remove image width and height attribute
function wcs_remove_img_attributes( $html ) {
    $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
    return $html;
add_filter( 'post_thumbnail_html', 'wcs_remove_img_attributes', 10 );
add_filter( 'image_send_to_editor', 'wcs_remove_img_attributes', 10 );

That’s all you need to do.


Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads