如果可以
我能把我毕生所学全记录下来

禁止wp博客头部加载s.w.org

很多同学在wp博客上面都发现了这段代码吧

<link rel='dns-prefetch' href='//s.w.org'>

这个是为了预加载一些表情用的,但是在我们大天朝是用不上的,反而影响我们网站的速度,建议静止他

可在后台找到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', 'wp_resource_hints', 2 );

这两种随便选一个添加就行了 最后再提供一个禁止加载表情的代码,我是已经添加上了的。

// Remove emoji script
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
add_filter( 'emoji_svg_url', '__return_false' );

 

未经允许也可转载:逍遥侯博客 » 禁止wp博客头部加载s.w.org

网友留言 抢沙发

评论前必须登录!

 

逍遥侯博客 大概一个互联网创业者的毕生所学