[wp-hackers] Is there a way to get the callback function name out of a shortcode _programmatically_?

J.D. Grimes jdg at codesymphony.co
Mon Nov 11 20:21:16 UTC 2013


Here is a function that does just that:

/**
 * Call a shortcode function by tag name.
 *
 * @author J.D. Grimes
 *
 * @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_func( $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 );
}

-J.D.

On Nov 11, 2013, at 3:12 PM, Haluk Karamete <halukkaramete at gmail.com> wrote:

> Is there a way to get the callback function name out of a shortcode
> _programmatically_?
> 
> for example
> 
> get_shortcode_callback_for('caption')
> 
> would return
> 
> "img_caption_shortcode"
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list