wordpress加载是s.w.org是什么网站?怎么禁用它以便加速?如果你是wordpress站长可能会发现你的网站html头部的head中加载了一个 dns-prefetch 代码,目的是从s.w.org预获取表情和头像,提高网页加载速度 ,但s.w.org在中国大陆根本无法访问,什么预获取和提高速度都是泡影,不仅没用处,反而可能会影响速度,所以要禁用它。
<link rel="dns-prefetch" href="//s.w.org">
这里给出两种办法禁用dns-prefetch:
将下面的代码添加到主题functions.php
模板中:
一、
将以下代码增加到主题文件functions.php模板中,保存即可
remove_action( 'wp_head', 'wp_resource_hints', 2 );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
add_filter( 'emoji_svg_url', '__return_false' );
将以下代码增加到主题文件functions.php模板中,保存即可
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 );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
add_filter( 'emoji_svg_url', '__return_false' );
清空缓存以后再次访问你的网站,就会发现快了很多。
最后给大家一个简单快捷的方法,查看wordpress的dns-pretch功能是否真的成功禁用了:
打开你的网站,然后右键查看网页源代码,Ctrl+F键 搜索s.w.org。如果有,就没禁用成功,如果搜索不到这个,那就禁用成功了。
北京万维提供wordpress拖拽式建站系统,支持中英文双语网站、企业网站、电商网站,外贸网站,欢迎合作!QQ442956988