Home > CMS Tutorial > WordPress > body text

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

藏色散人
Release: 2019-12-16 11:55:39
forward
2083 people have browsed it

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;>
Copy after login

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 );
Copy after login

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 );
Copy after login

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; );
Copy after login

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!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template