Last active
December 25, 2015 16:29
-
-
Save kristarella/7006219 to your computer and use it in GitHub Desktop.
Parses shortcode in WordPress image captions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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