Created
November 14, 2016 14:45
-
-
Save petersplugins/e75840cf2a325cf93e192640cc2b2665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This code snippet adds a meta box in the right sidebar of the post screen that lists all available shortcodes | |
// As we use a default WordPress admin meta box the box can be closed to save space and opened when needed | |
// Add a custom function to create the meta box | |
add_action( 'add_meta_boxes', 'add_shortcodes_metabox' ); | |
// This function adds the meta box | |
function add_shortcodes_metabox() { | |
add_meta_box( 'shortcodes-metabox', 'Available Shortcodes', 'display_shortcodes', 'post', 'side', 'high' ); | |
// The parameter 'post' makes sure the meta box shows only on the post screen | |
// If you want it also to appear on the pages screen change 'post' to array( 'post', 'page' ) | |
} | |
// This function creates the content of the meta box | |
// We don't have to care about all the other stuff because this is done by add_meta_box | |
function display_shortcodes() { | |
// The available shortcodes are stored in the global variable $shortcode_tags, so we need access to it | |
global $shortcode_tags; | |
// let's sort the list alphabetically | |
$available_shortcodes = $shortcode_tags; | |
ksort( $available_shortcodes ); | |
// show an unordered list of available shortcodes | |
echo '<ul>'; | |
foreach ( $available_shortcodes as $key => $value ) { | |
echo '<li>' . $key . '</li>'; | |
} | |
echo '</ul>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment