Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iqbalrony/5ee9d5b31a20ea262d42f7137a6b7ac6 to your computer and use it in GitHub Desktop.
Save iqbalrony/5ee9d5b31a20ea262d42f7137a6b7ac6 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