This question is an offshoot from the this discussion on removing dimension attributes from images. The solution code provided on that thread works very well except that it has the unfortunate side effect that any [caption]
shortcodes are striped from the image.
After several hours of digging through the core code, I found the cause of this. The wpeditimage TinyMCE plugin that's responsible for adding the [caption]
shortcode checks for width attributes in the shortcode and the img
tag. If it doesn't find them, it simply remove the caption. Since, this is done 'on the fly' with javascript in the TinyMCE editor, I can't think of any type of WordPress filter that would address this issue. I would be very happy to be proven wrong however. :)
As a final note, my temporary solution has been to use the following jQuery to strip all of the offending tags client side. This, in conjunction with a filter on img_caption_shortcode
to prevent a width style from being used there, seems to do the job. It's not pretty, but it's a band-aid for now. Anyone have a better idea?
// Strip width and height attributes from img, video, and object in the main article so we can have fluid images
var $fluid_items = $('.main-article-wrapper').find('img,video,object');
$fluid_items.removeAttr('width');
$fluid_items.removeAttr('height');