Sunday, July 7, 2013

How to Remove Width and Height Attributes From Inserted Images in wordpress post

I will show you how to delete added attributes (width and height) when you upload an image through the WordPress media uploader.

These are normally desirable, as it assists the browser in making the appropriate room for the image during layout. But if you want to remove the insert action from adding these attributes, you can add this code to your functions.php file of your template:

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;

Disqus Comments