WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a popup shortcode in admin panel. I already create the shortcode button and a popup on button click.

I want to display in the popup (not in the shortcode button), all my custom shortcodes that I have created in a dropdown list.

I really don't know how to get my shortcodes name with a loop like this for example:

<select id="shortcode-generator-select">
<option value="raw"></option>
<?php foreach( $shortcode as $shortcode ) : ?>
<option value="<?php echo $shortcode['name']; ?>"><?php echo $shortcode['title']; ?>    </option>
<?php endforeach; ?>

I just want to understand what is the way to create a popup shortcode generator.

share|improve this question

You get all shortcodes, there are registered in WordPress with the default function in the global $shortcode_tags. You can loop about this shortcodes and filter via tag or functiion.

foreach( $shortcode_tags as $tag => $function ) {


If the $function is a array, then can also read the parameters. See the source below. I think the source is easier to understand as my english ;)

     * Get all shortocdes and his data
     * @return String
    function get_shortcodes() {
            global $shortcode_tags;

            $style   = '';
            $output  = '<h4>Total Shortcodes: ' . count( $shortcode_tags ) . '</h4>';
            $output .= '<ol>';
            foreach( $shortcode_tags as $tag => $function ) {

                    $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';

                    if ( is_string( $function ) ) {

                            $function = '<code>' . $function . '</code>';

                    } else if ( is_array( $function ) ) {

                            $object = '';
                            $parameters = '';
                            if ( is_string( $function[0] ) ) {

                                    $object = $function[0];

                            } else if ( is_object( $function[0] ) ) {

                                    $object = get_class( $function[0] );
                                    foreach ( $function[0] as $parameter => $value ) {

                                            // if the array is empty
                                            if ( empty( $value ) )
                                                    $value = __( 'The Array is empty' );

                                            $parameters .=  '<li><code>' . $parameter . '</code> => <code>' . $value . '</code></li>';


                            if ( ! empty( $parameters ) )
                                    $parameters = '<br><strong>Parameters of class:</strong><ul>' . $parameters . '</ul>';
                            $function = '<code>' . $object . '::' . $function[1] . '</code>' . $parameters;
                    else {
                            $function = 'empty';

                    $output .= "<li$style><strong>Shortcode: </strong><code>$tag</code> <strong>Function: </strong>$function</li>";

            $output .= '</ol>';

            echo $output;
share|improve this answer
thank you for your answer. However I have two errors with your code. I can't write public before the function. It gives an error. If I remove public, I've got an error on the foreach loop: Invalid argument supplied for foreach()... – freaky Dec 27 '13 at 17:17
The code is a method of my debug plugin, the public string is always usable in a class. The follow problem is that, the global is empty. Init the function via a hook, like init or plugins_loaded - add_action( 'plugins_loaded', 'get_shortcodes' ); You can see the function in action with this plugin class. – bueltge Dec 27 '13 at 18:16

shortcodes get added to the global $shortcode_tags array as they are registred/added. Therefore you can access them thusly:

global $shortcode_tags;
foreach( $shortcode_tags as $shortcode ) {
 //do something

The array uses shortcode tags as the keys and the function called as the value, you'll probably have to figure out some way to further process them to get any meaningful information, and in fact since you state that you only want to list your own custom shortcodes, then this is probably the wrong approach anyhow.

share|improve this answer
thank you for your answer. I didn't success with your code... ANd is there a way to do it only with my custom shortcode. They are all in a same php file. – freaky Dec 27 '13 at 14:37
of course the code I posted didn't work. it isn't supposed to do anything. What did YOU do with it that isn't working? – Will the Web Mechanic Dec 27 '13 at 14:44
the same thing that I have in my question... – freaky Dec 27 '13 at 14:45
there is no array key called 'name' or 'title' in the $shortcode_tags array so of course it won't output anything. try something like this: foreach( $shortcode_tags as $key => $value ) { echo $key . ' ' . $value; } – Will the Web Mechanic Dec 27 '13 at 14:49
Ok. It works. Maybe to only echo my custom shortcode, I can filter $key and $value with my prefix theme name? – freaky Dec 27 '13 at 14:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.