Shortcode: display list of created shortcode in popup

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.

Read More

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

<tbody>
<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; ?>
</select>
</tbody> 

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

Related posts

2 comments

  1. 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;
        }
    
  2. 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.

Comments are closed.