Do you want to remove width and height attributes from images in posts? This snippet will remove all of the width and height attributes from your images in order to allow a responsive theme to handle the sizing.
Instructions
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
add_filter( 'post_thumbnail_html', 'remove_wps_width_attribute', 10 ); add_filter( 'image_send_to_editor', 'remove_wps_width_attribute', 10 ); function remove_wps_width_attribute( $html ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our WPtouch Review.
Thank You so much.
If you want to do this for responsive purposes a better way would be to resolve this issue with CSS, since CSS overwrites this attributes:
img{
max-width:100%;
height: auto;
}