removing inline styles from wp-caption div

Inline width and height attributes were never a huge problem with images in WordPress, since these were easily overwritten with CSS.

The problem I’m having is that any images with captions are being wrapped in a ID ‘attachment_(‘attachmentnumber’) and a class of ‘wp-caption’ AND they’re given inline CSS width and height properties.
This is a major pain in the butt, so I’d like to remove the inline styles of this div if at all possible.

2

To remove the inline width in a clean PHP-way could be done with a filter, as described in the source code: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/media.php#L1587

Returning a zero (or false) will remove it:

add_filter( 'img_caption_shortcode_width', '__return_false' );

Leave a Comment