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

Nikola Nikolov nikolov.tmw at gmail.com
Mon Nov 11 20:21:47 UTC 2013


You can access the global $shortcode_tags variable. If you want to wrap it
in a function, it would look something like this:

function get_shortcode_callback_for( $shortcode ) {
    return isset( $GLOBALS['shortcode_tags'][ $shortcode ] ) ?
$GLOBALS['shortcode_tags'][ $shortcode ] : false;
}

This will return the callback for the shortcode tag that you passed, or
false if such shortcode hasn't been registered yet.

Note, that the returned callback can be any type of
callable<http://php.net/manual/en/language.types.callable.php>,
So - you should use is_callable( $callback )<http://us3.php.net/is_callable> in
order to check if the parameter is actually callable.


On Mon, Nov 11, 2013 at 10: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