1.文件名称尽量使用英文命名
包括以下内容:
- 通过FTP上传的文件,包括php文件、图片文件、样式文件等等一律使用英文名称
- 在wordpress网站后台多媒体管理中心处上传的图片、视频、其他文件等,需一律改为英文命名,再上传
2.安装缓存插件
通过安装缓存插件,对css、js等文件进行缓存提高访问速度
Wp Super Cache插件地址:https://wordpress.org/plugins/wp-super-cache/
3.配置CDN加速
cdn加速可以带来较为明显的加速效果,原理是通过缓存静态资源文件在网络边缘节点,以便快速获取,提高网络访问延时
前提条件: 需要cdn加速服务器,常用有阿里云、七牛云
一个加速域名对应一个加速站点,配置好加速域名后,再通过wordpress安装插件Wp Super Cache使用
成功启用后可以看到所有的静态资源访问地址都被替换为cdn加速域名地址
4.优化配置,关闭在线安装主题、插件功能, 关闭谷歌字体等
打开wordpress主题根目录文件functions.php
, 例如:/wp-content/themes/twentyfourteen/functions.php, 在末尾添加以下代码
//wordpress后台禁用谷歌的字体api
class Uctheme_Disable_Google_Fonts {
public function __construct() {
add_filter( 'gettext_with_context', array( $this, 'disable_open_sans' ), 888, 4 );
}
public function disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
}
$disable_google_fonts = new Uctheme_Disable_Google_Fonts;
//谷歌字体移除
function remove_open_sans() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
wp_enqueue_style('open-sans','');
}
add_action( 'init', 'remove_open_sans' );
//头像处理
function get_avatar_uctheme( $avatar ) {
$avatar = preg_replace( "/http:\/\/(www|\d).gravatar.com/","http://gravatar.duoshuo.com",$avatar );
return $avatar;
}
add_filter( 'get_avatar', 'get_avatar_uctheme' );
//禁止插件或主题检查更新
function disable_plugin_request($a,$b,$c){
if(isset($b['body']['plugins']) || isset($b['body']['themes']))
return array('response'=>array('code'=>404));
}
add_filter("pre_http_request", disable_plugin_request,10,3);