How to insert pictures without hard coded dimensions?

How can I insert pictures into a post without any hard coded dimensions (e.g. <img src="" alt="" /> instead of <img src="" alt="" width="" height="" />)? I don’t want my users to switch to the HTML tab and remove the parameters by themselves, so I was wondering if there is any filter I can use to achieve this?

Note: I’m already inserting them in “Full size”.

Related posts

Leave a Reply

3 comments

  1. I don’t know if this is the best way to do this, but it works for me.

    In the functions.php of the theme you are using, put this:

    function remove_img_src($html)
    {
        $html = preg_replace('@(width|height)="([0-9])+" ?@i', '', $html);
    
        return $html;
    }
    
    add_filter('image_send_to_editor', 'remove_img_src', 10, 8);
    

    It uses regular expresions to change the output that is inserted in the editor.

  2. I found a solution in the meantime: wp_get_attachment_image_src() to get the src for the images. I think it ends up by being the easiest solution and it requires no filters.