Function to Change Remove Image Width/Height Attributes

* code #10 - remove width/height HTML attributes from images
* source -
* @param string
* @return string
function remove_image_size_atts($html) {
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
return $html;
add_filter('post_thumbnail_html', 'remove_image_size_atts', 10);
add_filter('image_send_to_editor', 'remove_image_size_atts', 10);

When you upload an image into WordPress the code will automatically include a width and height attribute onto the HTML tag. This data is often helpful when your page is still loading images, users will see a box placeholder instead of tiny 1×1 empty blocks.

But similarly there are responsive image techniques which sometimes require not specifying a width or height. It’s possible to upload images and then add the HTML yourself, but for users who don’t know how this is a great solution. You should be able to remove other attributes as well by listing them inside the regular expression.