有些插件慢,自己排查
本身wordpress没有问题
问题只是出自你的网络大环境
为什么这样说?
比如访问的
谷歌网络字体
wp的头像系统
还有自检更新
都是外网的,加上墙体,所以慢。
那么就来说说怎么禁用更新、网络字体和头像
1.禁用更新
点击后台 外观》主题编辑器 右侧列表中找到functions.php
下面代码添加到functions.php尾部
// 彻底关闭自动更新
add_filter('automatic_updater_disabled', '__return_true');
// 关闭更新检查定时作业
remove_action('init', 'wp_schedule_update_checks');
// 移除已有的版本检查定时作业
wp_clear_scheduled_hook('wp_version_check');
// 移除已有的插件更新定时作业
wp_clear_scheduled_hook('wp_update_plugins');
// 移除已有的主题更新定时作业
wp_clear_scheduled_hook('wp_update_themes');
// 移除已有的自动更新定时作业
wp_clear_scheduled_hook('wp_maybe_auto_update');
// 移除后台内核更新检查
remove_action( 'admin_init', '_maybe_update_core' );
// 移除后台插件更新检查
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
// 移除后台主题更新检查
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'load-update-core.php', 'wp_update_themes' );
remove_action( 'admin_init', '_maybe_update_themes' );
2.禁用网络字体
方法一上策,文件修改法
找到文件
/wp-includes/script-loader.php
查找
fonts.googleapis.com
编辑修改替换为
fonts.useso.com
或者将
$open_sans_font_url = "//fonts.googleapis.com…"
直接//注释掉
方法二中策,添加functions.php代码
function coolwp_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', 'coolwp_remove_open_sans_from_wp_core' );
方法三下策,安装Disable Google Fonts插件直接禁用
3.禁用头像
方法一,直接设置
打开后台 设置》讨论 拉到最下面,把使用头像勾去掉
方法二,添加functions.php代码
//官方Gravatar头像替换为duoshuo
function mytheme_get_avatar($avatar) {
$avatar = str_replace(array("www.gravatar.com","0.gravatar.com","1.gravatar.com","2.gravatar.com"),"gravatar.duoshuo.com",$avatar);
return $avatar;
}
add_filter( 'get_avatar', 'mytheme_get_avatar', 10, 3);