How to Remove the Width and Height Attributes From WP Image Uploader

Simply paste the following code into your theme functions.php:

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

Thanks to Damien for the cool hack!

Leave a Reply

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