• Resolved diegogusava

    (@diegogusava)


    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.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    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

    (@diegogusava)

    Hi @bcworkz,

    It was stretching the images … but you are right, I will fix it with css.

    Thank you

    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.
Viewing 3 replies - 1 through 3 (of 3 total)

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