前言:
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() {
- 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']);
- unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
- 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;
- $wp_admin_bar->remove_menu('wp-logo');
- }