WP for Wordpress

How to Remove Width and Height Attributes From wordpress post images



When you upload an image through the WordPress media uploader and then insert it into the editor, it comes with width and height attributes. These are normally desirable, as it assists the browser in making the appropriate room for the image during layout.

But some times the width and height attributes no longer needed to  a post attachment image or featured image so that situation you can remove with following snippet


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


Responses

0 Respones to "How to Remove Width and Height Attributes From wordpress post images"

Post a Comment

AddThis

 

Recent Comments

Return to top of page Copyright © 2014