Created
April 21, 2015 16:32
-
-
Save jerclarke/213de46aa04c95592d3e to your computer and use it in GitHub Desktop.
WordPress: Enable [shortcode] shortcode (real thing) in core WP 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 | |
/** | |
* Filter Caption shortcode attributes to enable the [shortcode] shortcode inside caption text | |
* | |
* WP doesn't run do_shortcode on the 'caption' text value parsed out of [caption], which means | |
* the [shortcode] shortcode doesn't work. | |
* | |
* We want [shortcode] to work but not necessarily any other shortcodes, so we will run do_shortcode() | |
* only if [shortcode] is present. Running do_shortcode() this way will process all shortcodes | |
* so beware any captions that for some reason also have a bad shortcode that will break formatting. | |
* | |
* @param array $out atts array as determined by WP to be returned after filtering | |
* @param array $pairs | |
* @param array $atts | |
* @return filtered $out atts | |
*/ | |
function gv_filter_shortcode_atts_caption_shortcode_shortcode($out, $pairs, $atts) { | |
/** | |
* If the shortcode shortcode is present then process all shortcodes | |
* Note: This will process ALL shortcodes which could give insane results | |
*/ | |
if (has_shortcode($out['caption'], 'shortcode')) : | |
$out['caption'] = do_shortcode($out['caption']); | |
endif; | |
return $out; | |
} | |
add_filter('shortcode_atts_caption', 'gv_filter_shortcode_atts_caption_shortcode_shortcode', 10, 3); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment