Saturday, June 16, 2012

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

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


When we upload images in WordPress using image uploader and insert that image into wordpress posts, WordPress always automatically include the image width and height attributes in the html <img> tag. But sometimes that can give us some problem, because that may not fit in our layout . So using the following code we can get rid of those height and width attributes.

Just paste the following code into  functions.php file under theme folder.

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

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off