WordPress 后台很多模块有时并不需要,使用下面的代码可以将它们屏蔽掉。
根据需要,将下面代码添加到当前主题functions.php模板文件中:
屏蔽左侧菜单
- remove_menus() {
- ;
- = (
- __(\’Dashboard\’),
- __(\’Posts\’),
- __(\’Media\’),
- __(\’Links\’),
- __(\’Pages\’),
- __(\’Appearance\’),
- __(\’Tools\’),
- __(\’Users\’),
- __(\’Settings\’),
- __(\’Comments\’),
- __(\’Plugins\’)
- );
- ();
- (prev()){
- = (\’ \’,[key()][0]);
- (([0], \'<\’) === FALSE) {
- (in_array([0] != NULL ? [0]: , )){
- unset([key()]);
- }
- } {
- = (\'<\’, [0]);
- (in_array([0] != NULL ? [0]: , )){
- unset([key()]);
- }
- }
- }
- }
- (is_admin()){
- add_action(\’admin_menu\’, \’remove_menus\’);
- }
删除子菜单
- remove_submenu() {
- remove_submenu_page(\’options-general.php\’, \’options-privacy.php\’);
- remove_submenu_page(\’themes.php\’, \’theme-editor.php\’);
- }
- (is_admin()){
- add_action(\’admin_init\’,\’remove_submenu\’);
- }
屏蔽后台更新模块
- wp_hide_nag() {
- remove_action( \’admin_notices\’, \’update_nag\’, 3 );
- }
- add_action(\’admin_menu\’,\’wp_hide_nag\’);
- remove_screen_options(){ false;}
- add_filter(\’screen_options_show_screen\’, \’remove_screen_options\’);
- add_filter( \’contextual_help\’, \’wpse50723_remove_help\’, 999, 3 );
- wpse50723_remove_help(, , ){
- ->remove_help_tabs();
- ;
- }
屏蔽后台仪表盘无用模块
- example_remove_dashboard_widgets() {
- ;
- unset([\’dashboard\’][\’side\’][\’core\’][\’dashboard_quick_press\’]);
- unset([\’dashboard\’][\’normal\’][\’core\’][\’dashboard_incoming_links\’]);
- unset([\’dashboard\’][\’normal\’][\’core\’][\’dashboard_plugins\’]);
- unset([\’dashboard\’][\’normal\’][\’core\’][\’dashboard_recent_comments\’]);
- unset([\’dashboard\’][\’side\’][\’core\’][\’dashboard_recent_drafts\’]);
- unset([\’dashboard\’][\’side\’][\’core\’][\’dashboard_primary\’]);
- unset([\’dashboard\’][\’side\’][\’core\’][\’dashboard_secondary\’]);
- unset([\’dashboard\’][\’normal\’][\’core\’][\’dashboard_right_now\’]);
- }
- add_action(\’wp_dashboard_setup\’, \’example_remove_dashboard_widgets\’ );
屏蔽后台页脚版本信息
- change_footer_admin () { ;}
- add_filter(\’admin_footer_text\’, \’change_footer_admin\’, 9999);
- change_footer_version() { ;}
- add_filter( \’update_footer\’, \’change_footer_version\’, 9999);
屏蔽后台左上LOGO
- annointed_admin_bar_remove() {
- ;
- ->remove_menu(\’wp-logo\’);
- }
- add_action(\’wp_before_admin_bar_render\’, \’annointed_admin_bar_remove\’, 0);
补:
add_action( \'admin_menu\', function(){ remove_menu_page( \'index.php\' ); //仪表盘 remove_menu_page( \'upload.php\' ); //多媒体 remove_menu_page( \'edit.php?post_type=page\' ); //页面 remove_menu_page( \'edit-comments.php\' ); //评论 remove_menu_page( \'plugins.php\' ); //插件 remove_menu_page( \'tools.php\' ); //工具 remove_menu_page( \'options-general.php\' ); //设置 });
暂无评论内容