How to Remove Width and Height Attributes From Inserted Images in WordPress

How to Remove Width and Height Attributes From Inserted Images.
remove_image_att
When we upload an image through the WordPress media uploader and then insert it into the tinyMCE editor, it comes with height & width attributes. But if you want to remove the insert action from adding these attributes, you can add this code to you functions.php file or a functionality plugin of your own making:

[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]

Author: Dheeraj Dhawan

I'm a web developer / PHP programmer. I am also working on custom plugin development of wordpress.

Leave a Reply

Your email address will not be published. Required fields are marked *