Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

3 Answers 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.

share|improve this answer
    
It doesn't seem to work when pulling the images from the post gallery, using wp_get_attachment_image. Any suggestions? –  João Ramos Apr 4 '12 at 20:14
1  
For what i see on the code, it seems that it can't be done without hardcode the changes. There's a filter in line 663, but on line 665 is harcoded the $hwstring wich contains that width/height definition. –  oso96_2000 Apr 4 '12 at 21:46
    
Any more ideas on how to solve this? –  João Ramos Apr 5 '12 at 15:39

Looks like you can do it with image captions, but not images at present:

From the wp-hackers mailing list:

I've got a filter I use that forces captions to be responsive on the frontend. Definitely cuts down on the headaches.

Gist here: https://gist.github.com/2243601

Drew

share|improve this answer
    
Thanks! In the meantime I've used wp_get_attachment_image_src() to get the src for the images. I think it ends up by being the most easy solution and it requires no filters. –  João Ramos Apr 6 '12 at 11:29
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.