簡碼(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
?>