Organizing shortcodes. How to display all of them and their attributes?

Inspect the global variable $shortcode_tags:

print '<pre>' . htmlspecialchars( print_r( $GLOBALS['shortcode_tags'], TRUE ) ) . '</pre>';

Output:

Array
(
     => img_caption_shortcode
     => img_caption_shortcode
     => gallery_shortcode
     => __return_false
    [contactform] => Array
        (
            [0] => T5_Contact_Form Object
                (
                    [debug:protected] => 
                    [base_name:protected] => t5-contact-form/t5-contact-form.php
                    [prefix:protected] => t5c
                    [address:protected] => 
                    [nonce_name:protected] => t5_contact_form_nonce
                    [hidden_field:protected] => t5_no_fill
                    [option_name:protected] => t5c_default_address
                )

            [1] => shortcode
        )

)

As you can see you get the shortcode name as key and the associated function as the value. If the function is an object you get the object with its properties and the associated function as an array.

I don’t see a way to get the default attributes. Maybe per Reflection API.

The attributes are defined inside of the functions. The registered shortcode doesn’t know anything about the inner workings of the associated function. And the default attributes can be ambiguous: they might be the result of another function call inside of the callback handler.

Leave a Comment