基于宝塔安装的wordpress进行优化
WP优化步骤
首先分享一下我的建议以及可以优化速度的有效措施
- 前端优化:使用CDN加速
- 前端优化:图片使用OSS/COS等第三方储存
- 后端优化:推荐使用Redis或Memcached缓存功能,和opcache进行PHP加速优化
- 后端优化:禁用一些WordPressAPI的自动更新任务及禁用谷歌字体
宝塔面板优化
这儿针对宝塔面板,提供一些优化建议。
首先PHP环境使用7.0版本数据库5.6以上最好
开启Redis和opcache拓展
宝塔环境里面下载Redis拓展
找到运行的PHP程序,安装opcache,和redis拓展
安装完扩展后,找到session配置,将缓存模式切换为redis(注意需要在服务器运营商哪里把6379进行放端)
调整数据库并发
数据库方面
在数据库性能设置,选择适合自己的服务器的优化方案
wp后台方面
在将下面代码添加到主题functions.php文件中:此步骤目的为禁用一些api的自动更新任务和关闭谷歌字体
// 关闭谷歌字体
function xintheme_remove_gutenberg_styles($translation, $text, $context, $domain)
{
if($context != 'Google Font Name and Variants' || $text != 'Noto Serif:400,400i,700,700i') {
return $translation;
}
return 'off';
}
// 彻底关闭自动更新
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' );
也可以安装一些插件加速
- WP ROCKET (自行百度下载安装,白嫖固好但还是希望能支持和尊重下正版和原创作者)
- All-in-One WP Migration 迁移站点
- Post Views Counter 查看阅读数
- WP Githuber MD Markdown在线编辑
- Yoast SEO SEO设置
- Redis Object Cache
本文摘抄自顽客:https://wkker.com/5033.html
评论区