Home  >  Article  >  CMS Tutorial  >  How to disable WordPress headers from loading s.w.org

How to disable WordPress headers from loading s.w.org

藏色散人
藏色散人forward
2019-12-16 11:55:392094browse

The following column WordPresstutorial will introduce to you how to disable the WordPress header from loading s.w.org. I hope it will be helpful to friends in need!

How to disable WordPress headers from loading s.w.org

Abstract

WordPress adds dns-prefetch in the header, which should be to pre-fetch emoticons and avatars from s.w.org. The purpose It is to improve the loading speed of web pages, but s.w.org is not accessible at all in China. Any pre-fetching or speed improvement are all in vain. Not only is it useless, but it may affect the speed, so ban it.

Prohibit WordPress header from loading s.w.org

After upgrading to WordPress 4.6, some children found that the header was loaded:

<link rel=&#39;dns-prefetch&#39; href=&#39;//s.w.org&#39;>

WordPress in the header The purpose of adding dns-prefetch is to pre-fetch emoticons and avatars from s.w.org. The purpose is to improve the loading speed of web pages. However, s.w.org is simply inaccessible in China. Any pre-fetching or speed-improving methods are in vain. Not only are they useless, but they are actually It might affect the speed, so disable it.

Add the following code to the theme functions.php template:

Method one

remove_action( &#39;wp_head&#39;, &#39;wp_resource_hints&#39;, 2 );

Method two

function remove_dns_prefetch( $hints, $relation_type ) {
if ( &#39;dns-prefetch&#39; === $relation_type ) {
return array_diff( wp_dependencies_unique_hosts(), $hints );
}
return $hints;
}
add_filter( &#39;wp_resource_hints&#39;, &#39;remove_dns_prefetch&#39;, 10, 2 );

Method two seems to have better compatibility .

Comes with an emoticon code that prohibits loading

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

Recommended tutorial column: "WordPress imitation site"

The above is the detailed content of How to disable WordPress headers from loading s.w.org. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zmingcx.com. If there is any infringement, please contact admin@php.cn delete