Skip to content

Instantly share code, notes, and snippets.

@ideag
Created February 28, 2013 09:05
Show Gist options
  • Save ideag/5055360 to your computer and use it in GitHub Desktop.
Save ideag/5055360 to your computer and use it in GitHub Desktop.
add_filter('img_caption_shortcode', 'tiny_img_caption_shortcode_filter',10,3);
function tiny_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;
preg_match('/(size\-[^ ",]+)/', $content,$m);
return '<figure id="' . $id . '" class="wp-caption ' . esc_attr($align) . ' '.$m[0].' align-'.$align.'" style="width: ' . $width . 'px;">'
. do_shortcode( $content ) . '<figcaption 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