Wordpress - make Wordpress image captions responsive
You're going to want to use:
@media (max-width: 988px){
.wp-caption {
/* Force the box to be 100% */
width: 100% !important;
}
#content .wp-caption a img {
/* Scale down if too big */
max-width: 99.03225806%; /* 614/620 */
height: auto;
}
}
Another possibility is to change the shortcode output so that the width is no longer hard-coded. Modifying the Codex example to have no width:
add_filter('img_caption_shortcode', 'my_img_caption_shortcode_filter',10,3);
/**
* Filter to replace the [caption] shortcode text with HTML5 compliant code
*
* @return text HTML content describing embedded figure
**/
function my_img_caption_shortcode_filter($val, $attr, $content = null)
{
extract(shortcode_atts(array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $val;
$capid = '';
if ( $id ) {
$id = esc_attr($id);
$capid = 'id="figcaption_'. $id . '" ';
$id = 'id="' . $id . '" aria-labelledby="figcaption_' . $id . '" ';
}
return '<figure ' . $id . 'class="wp-caption ' . esc_attr($align) . '" >'
. do_shortcode( $content ) . '<figcaption ' . $capid
. 'class="wp-caption-text">' . $caption . '</figcaption></figure>';
}
http://codex.wordpress.org/Function_Reference/add_filter#Example
Here's a much simpler and cleaner solution:
function my_img_caption_shortcode_width($width, $atts, $content)
{
return 0;
}
add_filter('img_caption_shortcode_width', 'my_img_caption_shortcode_width', 10, 3);