List All Registered Shortcodes Under Tools
Adds a Tools > Shortcodes screen listing every shortcode available on the site and the plugin, theme or function that provides it, so you know what can be used in content.
Opens WPIDE on
Code
add_action( 'admin_menu', function () {
add_management_page( 'Shortcodes', 'Shortcodes', 'manage_options', 'wpide-shortcodes', function () {
global $shortcode_tags;
$source = function ( $callback ) {
try {
if ( is_string( $callback ) && false !== strpos( $callback, '::' ) ) {
$callback = explode( '::', $callback );
}
$reflection = is_array( $callback ) ? new ReflectionMethod( $callback[0], $callback[1] ) : new ReflectionFunction( $callback );
$file = (string) $reflection->getFileName();
} catch ( ReflectionException $e ) {
return '';
}
if ( false !== strpos( $file, WP_PLUGIN_DIR ) ) {
return 'Plugin: ' . strtok( str_replace( WP_PLUGIN_DIR . '/', '', $file ), '/' );
}
if ( false !== strpos( $file, get_theme_root() ) ) {
return 'Theme: ' . strtok( str_replace( get_theme_root() . '/', '', $file ), '/' );
}
return false !== strpos( $file, ABSPATH . WPINC ) ? 'WordPress' : str_replace( ABSPATH, '', $file );
};
$tags = $shortcode_tags;
ksort( $tags );
echo '<div class="wrap"><h1>Shortcodes (' . count( $tags ) . ')</h1><table class="widefat striped"><thead><tr><th>Shortcode</th><th>Provided by</th></tr></thead><tbody>';
foreach ( $tags as $tag => $callback ) {
printf( '<tr><td><code>[%s]</code></td><td>%s</td></tr>', esc_html( $tag ), esc_html( $source( $callback ) ) );
}
echo '</tbody></table></div>';
} );
} );
Notes
Shortcodes registered only on the front end will not appear here.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.