Skip to content

Instantly share code, notes, and snippets.

@kristarella
Last active December 25, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristarella/7006219 to your computer and use it in GitHub Desktop.
Save kristarella/7006219 to your computer and use it in GitHub Desktop.
Parses shortcode in WordPress image captions
<?php
function nested_img_caption_shortcode($nada, $attr, $content = null) {
extract(
shortcode_atts(
array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
),
$attr,
'caption'
)
);
$caption = do_shortcode($caption); // process nested shortcodes
if ( 1 > (int) $width || empty($caption) )
return $content;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">' . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
add_filter('img_caption_shortcode', 'nested_img_caption_shortcode', 1, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment