Skip to content

Instantly share code, notes, and snippets.

@leanda
Created February 22, 2013 15:23
Show Gist options
  • Save leanda/5014169 to your computer and use it in GitHub Desktop.
Save leanda/5014169 to your computer and use it in GitHub Desktop.
WordPress: Remove caption width and add figcaption (use in functions.php)
/*--- Remove inline caption width for responsive themes ---*/
add_filter('img_caption_shortcode', 'my_img_caption_shortcode_filter',10,3);
function my_img_caption_shortcode_filter($val, $attr, $content = null)
{
extract(shortcode_atts(array(
'id' => '',
'align' => 'aligncenter',
'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>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment