显示WordPress当前可用的所有简码(Shortcode)

故里桃花落无踪,小楼轩窗山影重。若见瘦湖病西子,凋零秋风映山红。正是荷花成熟的季节,一朵朵荷花含苞怒放,满田野里的荷田闪烁着金光,一簇簇的荷花有的带着水珠乍开,有的含苞吐蕾,有的像个含羞的少女似开非开。

简码(Shortcode)是WordPress一个非常有用的功能,你可以先了解 WordPress Shortcode(简码)介绍及使用详解,今天要说的就是如何在WordPress后台显示所有当前可用的简码。

只要使用下面的PHP代码就可以输出所有简码:

1
2
3
4
5
6
7
8
<?php
        global $shortcode_tags;
        echo '
<pre>'; 
        print_r($shortcode_tags); 
        echo '</pre>
';
?>

<?php global $shortcode_tags; echo ' <pre>'; print_r($shortcode_tags); echo '</pre> '; ?>

如果你想在WordPress后台一个页面罗列所有可用简码,下载安装 view-all-shortcodes 插件,就可以在 后台 >设置>View All Shortcodes 下查看 。以下是该插件的所有代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/*
Plugin Name: Paulund View All Shortcodes
Plugin URI: http://www.paulund.co.uk
Description: View all the available shortcodes on your WordPress blog. This page will show you everything that is currently registered so you can use these in the text editor of WordPress
Version: 1
Author: Paul Underwood
Author URI: http://www.paulund.co.uk
*/
if(is_admin())
{
	// Create the Paulund toolbar
	$shortcodes = new View_All_Available_Shortcodes();
}
/**
 * View all available shrotcodes on an admin page
 *
 * @author
 **/
class View_All_Available_Shortcodes
{
	public function __construct()
	{
		$this->Admin();
	}
	/**
	 * Create the admin area
	 */
	public function Admin(){
		add_action( 'admin_menu', array(&$this,'Admin_Menu') );
	}
	/**
	 * Function for the admin menu to create a menu item in the settings tree
	 */
	public function Admin_Menu(){
		add_submenu_page(
			'options-general.php',
			'View All Shortcodes',
			'View All Shortcodes',
			'manage_options',
			'view-all-shortcodes',
			array(&$this,'Display_Admin_Page'));
	}
	/**
	 * Display the admin page
	 */
	public function Display_Admin_Page(){
		global $shortcode_tags;
        ?>
<div class="wrap">
<div id="icon-options-general" class="icon32"></div>
<h2>View All Available Shortcodes</h2>
<div class="section panel">
This page will display all of the available shortcodes that you can use on your WordPress blog.
<table class="widefat importers">
<tr>
<td><strong>Shortcodes</strong></td>
</tr>
        <?php
	        foreach($shortcode_tags as $code => $function)
	        {
	        	?>
<tr>
<td>[<?php echo $code; ?>]</td>
</tr>
	        	<?php
	        }
	    ?>
</table></div>
</div>
		<?php
	}
} // END class View_All_Available_Shortcodes
?>

<?php /* Plugin Name: Paulund View All Shortcodes Plugin URI: http://www.paulund.co.uk Description: View all the available shortcodes on your WordPress blog. This page will show you everything that is currently registered so you can use these in the text editor of WordPress Version: 1 Author: Paul Underwood Author URI: http://www.paulund.co.uk */ if(is_admin()) { // Create the Paulund toolbar $shortcodes = new View_All_Available_Shortcodes(); } /** * View all available shrotcodes on an admin page * * @author **/ class View_All_Available_Shortcodes { public function __construct() { $this->Admin(); } /** * Create the admin area */ public function Admin(){ add_action( 'admin_menu', array(&$this,'Admin_Menu') ); } /** * Function for the admin menu to create a menu item in the settings tree */ public function Admin_Menu(){ add_submenu_page( 'options-general.php', 'View All Shortcodes', 'View All Shortcodes', 'manage_options', 'view-all-shortcodes', array(&$this,'Display_Admin_Page')); } /** * Display the admin page */ public function Display_Admin_Page(){ global $shortcode_tags; ?> <div class="wrap"> <div id="icon-options-general" class="icon32"></div> <h2>View All Available Shortcodes</h2> <div class="section panel"> This page will display all of the available shortcodes that you can use on your WordPress blog. <table class="widefat importers"> <tr> <td><strong>Shortcodes</strong></td> </tr> <?php foreach($shortcode_tags as $code => $function) { ?> <tr> <td>[<?php echo $code; ?>]</td> </tr> <?php } ?> </table></div> </div> <?php } } // END class View_All_Available_Shortcodes ?>

本文显示WordPress当前可用的所有简码(Shortcode)到此结束。船的命运在于漂泊;帆的命运在于追风逐浪;人生的命运在于把握,把握信人生,方能青春无愧。小编再次感谢大家支持!

标签: WordPress Shortcode