### [如何禁止WordPress头部加载s.w.org](https://www.prosaas.cn/article/9343) **Published:** 2019-12-16T03:55:39 **Author:** 5201314 **Excerpt:** 下面由WordPress教程栏目给大家介绍禁止WordPress头部加载s.w.org的方法,希望对需要的朋友… 下面由**WordPress****教程**栏目给大家介绍禁止WordPress头部加载s.w.org的方法,希望对需要的朋友有所帮助! ![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212132256980.jpg) **摘要** WordPress在头部添加dns-prefetch,应该是为了从s.w.org预获取表情和头像,目的是提高网页加载速度 ,但s.w.org国内根本无法访问,什么预获取、什么提高速度,都是泡影,不仅没用处,反而可能会影响速度,那就禁止它。 **禁止WordPress头部加载s.w.org** 升级到WordPress 4.6之后,有童鞋发现头部加载了一个: WordPress在头部添加dns-prefetch,应该是为了从s.w.org预获取表情和头像,目的是提高网页加载速度 ,但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 ); 方法二貌似兼容性更好些。 附带一个禁止加载表情代码 // 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' ); 推荐教程栏目:《**WordPress仿站**》 以上就是如何禁止WordPress头部加载s.w.org的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** php, WordPress **Categories:** WordPress ---