Skip to content

Instantly share code, notes, and snippets.

@leanda
Created February 21, 2013 15:58
Show Gist options
  • Save leanda/5005688 to your computer and use it in GitHub Desktop.
Save leanda/5005688 to your computer and use it in GitHub Desktop.
WordPress: Remove inline styling of captions, helpful for responsive themes.
add_shortcode('wp_caption', 'fixed_img_caption_shortcode');
add_shortcode('caption', 'fixed_img_caption_shortcode');
function fixed_img_caption_shortcode($attr, $content = null) {
// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' ) return $output;
extract(shortcode_atts(array(
'id'=> '',
'align' => 'alignnone',
'width' => '',
'caption' => ''), $attr));
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
. '">'
. do_shortcode( $content ) . '<p class="wp-caption-text">'
. $caption . '</p></div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment