dns-prefetch

投稿日:2022-07-09 投稿者:PS カテゴリ:その他 タグ: , , ,

WordPress Ver.4.6 以降、<head> に dns-prefetch が出力されるようになったらしい。
これは、絵文字画像などの外部サイトからのファイル参照を高速化するのが目的らしい。
WordPress標準の絵文字や外部参照の画像などが無い場合は、あまり意味がない。

Tips

emoji を無効にする方法

add_filter( 'emoji_svg_url', '__return_false' );

dns-prefetch の出力を止める方法

// functions.php への記述
add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );
function remove_dns_prefetch( $hints, $relation_type ) {
	if ( 'dns-prefetch' === $relation_type ) {
		return array_diff( wp_dependencies_unique_hosts(), $hints );
	}
	return $hints;
}
  • wp_resource_hints()