Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Created March 8, 2021 09:56
Show Gist options
  • Save obiPlabon/d3afd614fbadcb6fbe3372cd5415c819 to your computer and use it in GitHub Desktop.
Save obiPlabon/d3afd614fbadcb6fbe3372cd5415c819 to your computer and use it in GitHub Desktop.
Call a shortcode function by tag name
<?php
/**
* Call a shortcode function by tag name.
*
* @param string $tag The shortcode whose function to call.
* @param array $atts The attributes to pass to the shortcode function. Optional.
* @param array $content The shortcode's content. Default is null (none).
*
* @return string|bool False on failure, the result of the shortcode on success.
*/
function do_shortcode_callback( $tag, array $atts = array(), $content = null ) {
global $shortcode_tags;
if ( ! isset( $shortcode_tags[ $tag ] ) ) {
return false;
}
return call_user_func( $shortcode_tags[ $tag ], $atts, $content, $tag );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment