Remove Width and Height Attributes From Inserted Images in WordPress

When you insert an image inside a post, WordPress automatically adds height and width attributes to that image.

Must Read : How to Display the Total Number of Comments in WordPress?

Normally, this is desirable as it assist web browsers to make proper room for the image within the design. However, in some cases you may want remove these hard coded dimensions, specially if it creates a conflict with your theme design.

To remove height and width attributes from images, copy the following code and paste it inside your functions.php file located inside your theme directory.

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

Source : http://wpdailybits.com/blog/remove-the-width-and-height-attributes-from-wp-image-uploader/539

0 Comments

Leave a Comment.