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”.

3 s
3

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.

Leave a Reply

Your email address will not be published. Required fields are marked *