[WordPress教程]WordPress屏蔽后台仪表盘无用模块+导航栏+菜单,加快wordpress后台速度

后台很多功能都是没必要存在,而且加载一个链接后台打开速度就会越慢
以下代码是自用,精简了很多自己用不到的菜单或者功能,自己添加时候自行选择,做了注释

编辑当前使用 wordpress主题 模板中的 functions.php 文件,根据需要添加下列代码:

/******屏蔽wordpress后台仪表盘无用模块+导航栏+菜单*******/
function disable_dashboard_widgets() { 
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');//近期评论 
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'normal');//近期草稿
remove_meta_box('dashboard_primary', 'dashboard', 'core');//wordpress博客 
remove_meta_box('dashboard_secondary', 'dashboard', 'core');//wordpress其它新闻 
remove_meta_box('dashboard_right_now', 'dashboard', 'core');//wordpress概况 
remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');//wordresss链入链接 
remove_meta_box('dashboard_plugins', 'dashboard', 'core');//wordpress链入插件 
remove_meta_box('dashboard_activity', 'dashboard', 'core');//wordpress活动模块
remove_meta_box('dashboard_quick_press', 'dashboard', 'core');//wordpress快速发布 
} 
add_action('admin_menu', 'disable_dashboard_widgets');
//屏蔽wordpress后台更新模块
function wp_hide_nag() {remove_action( 'admin_notices', 'update_nag', 3 );}
add_action('admin_menu','wp_hide_nag');
//移除 WordPress 加载的JS和CSS链接中的版本号
function wpdaxue_remove_cssjs_ver( $src ) {
if( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
add_filter( 'script_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
//移除自动保存
wp_deregister_script('autosave');
//移除修订版本
remove_action('post_updated','wp_save_post_revision' );
//后台禁用Google Open Sans字体,加速网站
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}return $translations;
}
/******wordpress后台删除不用模块+菜单*******/
function remove_submenu() {
// 删除”设置”下面的子菜单”隐私”
remove_submenu_page('options-general.php', 'options-privacy.php');
// 删除”左侧菜单”下面的子菜单
remove_submenu_page('themes.php', 'theme-editor.php');//编辑页面
remove_submenu_page('themes.php', 'Findex.php');//自定义页面
remove_submenu_page('themes.php', 'widgets.php');//小工具页面
remove_submenu_page('plugins.php', 'plugin-editor.php');//去除插件plugin-editor页面 
remove_submenu_page('plugins.php', 'plugin-install.php');//去除插件安装插件页面 
remove_submenu_page('options-general.php', 'privacy.php');//去除设置里面隐私页面
remove_submenu_page('options-general.php', 'options-media.php');//去除设置里面媒体页面
}
if (is_admin()){
add_action('admin_init','remove_submenu');
}
//删除后台左侧不用菜单  
function lvr8_remove_menu_page() {  
    remove_menu_page('tools.php');  //删除左侧菜单-工具
    remove_menu_page('users.php');  //删除左侧菜单-用户
	remove_menu_page('upload.php'); //删除左侧菜单-媒体
}  
add_action( 'admin_menu', 'lvr8_remove_menu_page' );  
//移除WordPress后台底部左文字
add_filter('admin_footer_text', '_admin_footer_left_text');
function _admin_footer_left_text($text) {
	$text = '';
	return $text;
}
//移除WordPress后台底部右文字
add_filter('update_footer', '_admin_footer_right_text', 11);
function _admin_footer_right_text($text) {
	$text = '';
	return $text;
}
//精简 WordPress 前后台顶部工具栏
function my_edit_toolbar($wp_toolbar) {
	$wp_toolbar->remove_node('wp-logo'); //去掉 WordPress LOGO
	$wp_toolbar->remove_node('site-name'); //去掉网站名称
	$wp_toolbar->remove_node('updates'); //去掉更新提醒
	$wp_toolbar->remove_node('comments'); //去掉评论提醒
    $wp_toolbar->remove_node('new-content'); //去掉新建文件
	$wp_toolbar->remove_node('top-secondary'); //用户信息
}
add_action('admin_bar_menu', 'my_edit_toolbar', 999);
//屏蔽 WP 后台“显示选项”和“帮助”选项卡(选项卡在发布新文章时有用,自行选择)
function remove_screen_options(){ return false;}
    //add_filter('screen_options_show_screen', 'remove_screen_options');//后台选项卡按钮
    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 wp_remove_open_sans_from_wp_core() {
	wp_deregister_style( 'open-sans' );
	wp_register_style( 'open-sans', false );
	wp_enqueue_style('open-sans','');
}
add_action( 'init', 'wp_remove_open_sans_from_wp_core' );
add_action( 'admin_bar_menu', 'cwp_remove_wp_logo_from_admin_bar_new', 25 );
function cwp_remove_wp_logo_from_admin_bar_new( $wp_admin_bar ) {
    $wp_admin_bar->remove_node( 'wp-logo' );
}
function cwp_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_right_now']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
add_action('wp_dashboard_setup', 'cwp_remove_dashboard_widgets',11 );

请注意左侧菜单和左侧菜单”下面的子菜单,自行选择是否需要留下的功能,因为这些功能对我没用,所有在上面代码中都屏蔽了,自行选择


  • 发表评论

      • 置顶评论
      • 基本上用上这代码,后台打开速度快了不止一倍

        Tmd回复私信
      • Tmd

        基本上用上这代码,后台打开速度快了不止一倍

        回复私信