禁止WP头部加载s.w.org

升级到4.6版本之后,查看博客首页源代码时,会发现多出一个<link rel=’dns-prefetch’ href=’//s.w.org’>,这是新版添加了dns-prefetch功能,其从s.w.org网站调用表情和头像等数据,加快博客访问速度。

不过国内不可以访问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 );

如您不会修改,也可以联系我帮忙修改!

 

禁止WordPress头部加载s.w.org:

方法一:
remove_action( ‘wp_head’, ‘wp_resource_hints’, 2 );

方法二:

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’ );

============================================================================
禁止加载:<link rel=’https://api.w.org/’ href=’http://blog.com/wp-json/’ />

//移除wp-json
add_filter(‘rest_enabled’, ‘__return_false’);
add_filter(‘rest_jsonp_enabled’, ‘__return_false’);
remove_action( ‘wp_head’, ‘rest_output_link_wp_head’, 10 );
remove_action( ‘wp_head’, ‘wp_oembed_add_discovery_links’, 10 );
remove_action( ‘template_redirect’, ‘rest_output_link_header’, 11, 0 );