Remove Width and Height Attributes from wordpress content area

October 12, 2012

When you upload images using WordPress image uploader and insert it into your post/page, it will include the image width and height attribute in the tag.if you want to remove this automatic image width and height attribute from image, you can add this code to you functions.php

[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;
}
[/php]

Credit

Also there is a css solution for you also

[php]
/* Images */
.entry-content img,
.comment-content img,
.widget img {
max-width: 97.5%; /* Fluid images for posts, comments, and widgets */
}
img[class*="align"],
img[class*="wp-image-"] {
height: auto; /* Make sure images with WordPress-added height and width >attributes are scaled correctly */
}
img.size-full {
max-width: 97.5%;
width: auto; /* Prevent stretching of full-size images with height and >>width attributes in IE8 */
}

[/php]

Credit

Related Posts

Let Us Work Together

Let us Plan Your Website or Digital Strategy Together

Start My Proposal Now →