WordPress 後臺很多模組有時並不需要,使用下面的程式碼可以將它們遮蔽掉。
根據需要,將下面程式碼新增到當前主題 functions.php 模板檔案中:
遮蔽左側選單:
- function remove_menus() {
- global $menu;
- $restricted = array(
- __('Posts'),
- __('Links'),
- __('Appearance'),
- __('Users'),
- __('Comments'),
- );
- end ($menu);
- while (prev($menu)){
- $value = explode(' ',$menu[key($menu)][0]);
- if(strpos($value[0], '<') === FALSE) {
- if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){
- unset($menu[key($menu)]);
- }else {
- $value2 = explode('<', $value[0]);
- if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){
- $menu[key($menu)]);
- }
- }
- if (is_admin()){
- // 遮蔽左側選單
- add_action('admin_menu', 'remove_menus');
-
- function remove_submenu() {
- // 刪除」 設定」 下面的子選單」 隱私」
- remove_submenu_page('options-general.php', 'options-privacy.php');
- // 刪除」 外觀」 下面的子選單」 編輯」
- remove_submenu_page('themes.php', 'theme-editor.php');
- if (is_admin()){
- //刪除子選單
- add_action('admin_init','remove_submenu');
-
- function wp_hide_nag() {
- }
遮蔽 WP 後臺 「顯示選項」 和 「幫助」 選項卡:
- function remove_screen_options(){ return false;}
- add_filter( 'contextual_help', 'wpse50723_remove_help', 999, 3 );
- function wpse50723_remove_help($old_help, $screen_id, $screen){
- $screen->remove_help_tabs();
- return $old_help;
- }
遮蔽後臺儀表盤無用模組:
- function example_remove_dashboard_widgets() {
- // Globalize the metaboxes array, this holds all the widgets for wp-admin
- global $wp_meta_boxes;
- // 以下這一行程式碼將刪除 "快速釋出" 模組
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
- // 以下這一行程式碼將刪除 "引入連結" 模組
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
- // 以下這一行程式碼將刪除 "外掛" 模組
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
- // 以下這一行程式碼將刪除 "近期評論" 模組
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
- // 以下這一行程式碼將刪除 "近期草稿" 模組
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
- // 以下這一行程式碼將刪除 "WordPress 開發日誌" 模組
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
- // 以下這一行程式碼將刪除 "其它 WordPress 新聞" 模組
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
- // 以下這一行程式碼將刪除 "概況" 模組
- unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
- add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );
遮蔽後臺頁尾版本資訊:
- function change_footer_admin () {return '';}
- function change_footer_version() {return '';}
遮蔽後臺左上 LOGO:
- function annointed_admin_bar_remove() {
- global $wp_admin_bar;
- /* Remove their stuff */
- $wp_admin_bar->remove_menu('wp-logo');
- }