Remove Width and Height From Inserted Images with Hook

Remove Width and Height From Inserted Images with Hook

In WordPress When we add an image in the editor or add the image as included images by default it comes with an elevation and also size. If you intend to remove this elevation and also width associate you can add the complying with code in function.php. It’ll additionally eliminate the elevation and also the width of functions picture too.

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