众所周知WordPress建站系统服务器是在国外,当用户在国内访问国外的资源时,访问页面速度必然会下降很多,比如谷歌字体,后台系统自带的图片、缓存、API、等等之类因素都会影响页面加载速度。
复制下面禁用谷歌字体代码放入到主题文件下的functions.php下面,注意是需要放在<?php 代码下面(修改之前建议先备份文件,以免发生意外的错误。)
// 屏蔽谷歌字体 add_filter( 'gettext_with_context', 'wpjam_disable_google_fonts', 888, 4); function wpjam_disable_google_fonts($translations, $text, $context, $domain ) { $google_fonts_contexts = array('Open Sans font: on or off','Lato font: on or off','Source Sans Pro font: on or off','Bitter font: on or off'); if( $text == 'on' && in_array($context, $google_fonts_contexts ) ){ $translations = 'off'; } return $translations; } // 禁止古腾堡加载 Google 字体 add_action('admin_print_styles', function(){ wp_deregister_style('wp-editor-font'); wp_register_style('wp-editor-font', ''); });
下面是其他一些禁用加载的代码,根据个人需求选择性使用,每个代码之前都有备注含义,同样是放入到主题文件下的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' ); // 替换 Gravatar 头像的服务器地址 function mytheme_get_avatar( $avatar ) { $avatar = preg_replace( "/http://(www|d).gravatar.com/","替换地址",$avatar ); return $avatar; } add_filter( 'get_avatar', 'mytheme_get_avatar' ); // 移除后台界面右上角的选项 add_action('in_admin_header', function(){ add_filter('screen_options_show_screen', '__return_false'); add_filter('hidden_columns', '__return_empty_array'); });// 移除后台界面右上角的帮助 add_action('in_admin_header', function(){ global $current_screen; $current_screen->remove_help_tabs(); }); // 屏蔽站点管理员邮箱验证功能 add_filter('admin_email_check_interval', '__return_false'); // 屏蔽站点Feed function wpjam_feed_disabled() { wp_die('Feed已经关闭, 请访问网站<a href="'.get_bloginfo('url').'">首页</a>!'); } add_action('do_feed', 'wpjam_feed_disabled', 1); add_action('do_feed_rdf', 'wpjam_feed_disabled', 1); add_action('do_feed_rss', 'wpjam_feed_disabled', 1); add_action('do_feed_rss2', 'wpjam_feed_disabled', 1); add_action('do_feed_atom', 'wpjam_feed_disabled', 1); // 屏蔽前台语言包,提升加载速度 add_filter('locale', function($locale) { $locale = ( is_admin() ) ? $locale : 'en_US'; return $locale; }); // 删除 wp_head 中不重要的代码 remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'start_post_rel_link'); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'adjacent_posts_rel_link'); // 禁用 Emoji 表情符合功能 remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('embed_head', 'print_emoji_detection_script'); remove_filter('the_content_feed', 'wp_staticize_emoji'); remove_filter('comment_text_rss', 'wp_staticize_emoji'); remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); add_filter( 'emoji_svg_url', '__return_false' );
1.后台插件库中搜索:WPJAM BASIC 并且安装。
2.后台设置根据个人需求设置勾选需要禁用的选项,保存即可实现WordPress网站加速。
使用了以上任意一种WordPress网站优化加速方法以后,会感觉到网站明显速度有所提升,前提是需要保证你网站架设的服务器也能正常流畅运行。
本文由网友投稿或聚码屋整理自网络,如转载请注明出处:https://www.ym3.net/2570.html;
本站发布的内容若侵犯到您的权益,请邮件联系 cnzz8#outlook.com 删除,我们将及时处理!
本站大部分下载资源收集于网络,不保证其完整性以及安全性,请下载后自行测试。
本站资源仅供学习和交流使用,版权归资源原作者所有,请在下载后24小时之内自觉删除。
若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,与本站无关。
还没有评论,快来说点什么吧~