Title: Remove Image Width and Height
Last modified: August 20, 2020

---

# Remove Image Width and Height

 *  Resolved [diegogusava](https://wordpress.org/support/users/diegogusava/)
 * (@diegogusava)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/remove-image-width-and-height/)
 * Hi, after I updated wordpress to 5.5 the following code doesn’t work anymore.
 *     ```
         function remove_width_attribute($html)
       {
           $html = preg_replace('/(width|height)="\d*"\s/', "", $html);
           return $html;
       }
   
       add_filter('post_thumbnail_html', 'remove_width_attribute', 10);
       add_filter('image_send_to_editor', 'remove_width_attribute', 10);
       ```
   
 * Actually in the Editor I don’t see width and height …. but when I open the blog
   post now, the image / figure contains width and height and that is not what I
   am expecting, can someone help me out?
    Thanks
    -  This topic was modified 5 years, 9 months ago by [diegogusava](https://wordpress.org/support/users/diegogusava/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/remove-image-width-and-height/#post-13289708)
 * The block editor does not fire “image_send_to_editor”. It’s only applied in the
   classic editor. “post_thumbnail_html” should still work AFAIK since featured 
   image output is independent from editor content. I’m not sure if there is an 
   equivalent to “image_send_to_editor”, the block editor works very differently
   than classic editor.
 * You might try removing the offending attributes from the data filtered by “wp_kses_allowed_html”.
   Untested. You can always filter “the_content”, but doing preg_replace() on all
   content is not very efficient. You’re better off doing so when the post is saved
   through “wp_insert_post_data” filter.
 * Out of curiosity, how are the attributes a problem? CSS overrides the attribute
   values, they are essentially a legacy feature AFAIK.
 *  Thread Starter [diegogusava](https://wordpress.org/support/users/diegogusava/)
 * (@diegogusava)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/remove-image-width-and-height/#post-13293609)
 * Hi [@bcworkz](https://wordpress.org/support/users/bcworkz/),
 * It was stretching the images … but you are right, I will fix it with css.
 * Thank you
 *  [ostarel](https://wordpress.org/support/users/ostarel/)
 * (@ostarel)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/remove-image-width-and-height/#post-13343280)
 * Hi!
 * I fix this stretching issue by adding following lines at the beginning of my 
   css file
 *     ```
       figure > img {
       	width: auto;
       	height: auto;
       }
       ```
   
    -  This reply was modified 5 years, 8 months ago by [ostarel](https://wordpress.org/support/users/ostarel/).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Remove Image Width and Height’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 3 participants
 * Last reply from: [ostarel](https://wordpress.org/support/users/ostarel/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/remove-image-width-and-height/#post-13343280)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
