wordpress优化细节:屏蔽s.w.org和移除emoji加快打开速度

在使用wordpress主题时,经常发现使用国外的主题打开网站很慢,尤其是文章页,后来发现这是由于Wordpress的服务器在国外,在wordpress 4.2版本之后增加了emoji表情外部调用,后为了提高页面的加载速度,wordprses 4.6版本之后在head中增加dns-prefetch用来从s.w.org获取表情和头像,但是由于国内网络访问问题,在打开网页时会发现在浏览器左下角一直在显示“等待s.w.org…”或“正在获取s.w.org..”之类的提示,也就是说这东西在国内不仅没用处还影响网页加载速度。而且对于部分wordpress用户来说并不需要这东西,那么禁止它就非常有必要.

 

remove_action('wp_head', 'print_emoji_detection_script', 7 );
remove_action('admin_print_scripts','print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
//禁止加载s.w.org并移动dns-prefetch
function remove_dns_prefetch( $hints, $relation_type ) {
if ( 'dns-prefetch' === $relation_type ) {
return array_diff( wp_dependencies_unique_hosts(), $hints );
}
return $hints;
}
add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );

  

posted @ 2019-07-04 18:00  胡小易  阅读(605)  评论(0编辑  收藏  举报