I'm working on a site based on a fluid width css template which sets a max-width on images to the width of the column containing them, and I need to remove the inline width and height dimension attributes that WordPress adds to images.
I'm doing it with my featured images with this filter:
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 3 );
function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
I know I can apply the same filter to the_content, if necessary. But is there a better way of doing this?
img_caption_shortcode
, which processes the caption shortcode, requires that a width be specified in the caption shortcode attributes. Otherwise, it skips the caption altogether and just returns the content wrapped inside the[caption]
shortcode tags.img_caption_shortcode
. Writing up the code for a function like that is more than I can fit into comments here, though.img_caption_shortcode
will be enough the solve the problem.