wordpress移除emoji并禁止头像加载s.w.org

WordPress教程 1590

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

wordpress移除emoji并禁止头像加载s.w.org

把下面的代码放到主题的functions.php文件

1
2
3
4
5
6
7
8
9
10
11
12
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 );

保存文件即可。

精品推荐: