function do_shortcode_by_tags($content, $tags)
{
global $shortcode_tags;
$_tags = $shortcode_tags;
foreach ($_tags as $tag => $callback) {
if (!in_array($tag, $tags))
unset($shortcode_tags[$tag]);
}
$shortcoded = do_shortcode($content);
$shortcode_tags = $_tags;
return $shortcoded;
}
This works by filtering the global $shortcode_tags, starting do_shortcode()and then returning everything as it was before.
Usage example;
$comment = do_shortcode_by_tags($comment, array('tag_1', 'tag_2'));
This will apply the short code tag_1and to the comment tag_2.
source
share