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

WordPress 4.6之后,有童鞋发现头部加载了一个:

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

如何去除呢?这里介绍两个方法将下面的代码添加到主题functions.php模板中:

其一:

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

但是实践中发现方法二其实兼容性好些.所以 建议用方法二.

禁止加载wordpress自带表情(依然是直接扔到funcitons.php中):

// 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' );

参考:https://wordpress.org/support/topic/remove-the-new-dns-prefetch-code/