升级到WordPress 4.6之后,有童鞋发现头部加载了一个:
<link rel=\’dns-prefetch\’ href=\’//s.w.org\’>
WordPress在头部添加dns-prefetch,应该是为了从预获取表情和头像,目的是提高网页加载速度 ,但什么预获取、什么提高速度,都是泡影,不仅没用处,反而可能会影响速度,那就禁止它。
将下面的代码添加到主题functions.php模板中:
方法一
- remove_action( \’wp_head\’, \’wp_resource_hints\’, 2 );
方法二
- remove_dns_prefetch( , ) {
- ( \’dns-prefetch\’ === ) {
- ( wp_dependencies_unique_hosts(), );
- }
- ;
- }
- 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\’ );
参考:https://wordpress.org/support/topic/remove-the-new-dns-prefetch-code/
暂无评论内容