WordPress 後臺很多模組有時並不需要,使用下面的程式碼可以將它們遮蔽掉。

根據需要,將下面程式碼新增到當前主題 functions.php 模板檔案中:

遮蔽左側選單:

  1. function remove_menus() {  
  2. global $menu;  
  3.     $restricted = array(  
  4.         __('Posts'),  
  5.         __('Links'),  
  6.         __('Appearance'),  
  7.         __('Users'),  
  8.         __('Comments'),  
  9.     );  
  10. end ($menu);  
  11.     while (prev($menu)){  
  12. $value = explode(' ',$menu[key($menu)][0]);  
  13.         if(strpos($value[0], '<') === FALSE) {  
  14. if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){  
  15.                 unset($menu[key($menu)]);  
  16.         }else {  
  17. $value2 = explode('<', $value[0]);  
  18.             if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){  
  19. $menu[key($menu)]);  
  20.             }  
  21.     }  
  22. if (is_admin()){  
  23. //  遮蔽左側選單  
  24.     add_action('admin_menu', 'remove_menus');  
    1. function remove_submenu() {  
    2. //  刪除」 設定」 下面的子選單」 隱私」  
    3.     remove_submenu_page('options-general.php', 'options-privacy.php');  
    4. //  刪除」 外觀」 下面的子選單」 編輯」  
    5.     remove_submenu_page('themes.php', 'theme-editor.php');  
    6. if (is_admin()){  
    7. //刪除子選單  
    8.     add_action('admin_init','remove_submenu');  
      1. function wp_hide_nag() {  
    9. }  

遮蔽 WP 後臺 「顯示選項」 和 「幫助」 選項卡:

  1. function remove_screen_options(){ return false;}  
  2.     add_filter( 'contextual_help', 'wpse50723_remove_help', 999, 3 );  
  3. function wpse50723_remove_help($old_help$screen_id$screen){  
  4.     $screen->remove_help_tabs();  
  5. return $old_help;  
  6. }  

遮蔽後臺儀表盤無用模組:

  1. function example_remove_dashboard_widgets() {  
  2. // Globalize the metaboxes array, this holds all the widgets for wp-admin  
  3.     global $wp_meta_boxes;  
  4. //  以下這一行程式碼將刪除 "快速釋出"  模組  
  5.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);  
  6. //  以下這一行程式碼將刪除 "引入連結"  模組  
  7.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);  
  8. //  以下這一行程式碼將刪除 "外掛"  模組  
  9.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);  
  10. //  以下這一行程式碼將刪除 "近期評論"  模組  
  11.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);  
  12. //  以下這一行程式碼將刪除 "近期草稿"  模組  
  13.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);  
  14. //  以下這一行程式碼將刪除 "WordPress  開發日誌"  模組  
  15.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);  
  16. //  以下這一行程式碼將刪除 "其它 WordPress  新聞"  模組  
  17.     unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);  
  18. //  以下這一行程式碼將刪除 "概況"  模組  
  19.     unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);  
  20. add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );  

遮蔽後臺頁尾版本資訊:

  1. function change_footer_admin () {return '';}  
  2. function change_footer_version() {return '';}  

遮蔽後臺左上 LOGO:

  1. function annointed_admin_bar_remove() {  
  2. global $wp_admin_bar;  
  3.         /* Remove their stuff */  
  4. $wp_admin_bar->remove_menu('wp-logo');  
  5. }