wordpress去掉<link rel='dns-prefetch' href='//s.w.org' />

  我们在用wordpress建站时经常会看到<link rel='dns-prefetch' href='//s.w.org' />,应该是为了从s.w.org预获取表情和头像,目的是提高网页加载速度 ,但s.w.org国内根本无法访问,怎么把这个东西去掉呢?有几种方法:

  1、在主题function.php文件中屏蔽

1
remove_action( 'wp_head', 'wp_resource_hints', 2 );

  或者下面这种改造过的方法,兼容性会好点

1
2
3
4
5
6
7
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 );

  2、直接在文件去除相关函数,/wp-includes/general-template.php大概2903行全部注释  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//      foreach ( $urls as $key => $url ) {
//          $atts = array();
//
//          if ( is_array( $url ) ) {
//              if ( isset( $url['href'] ) ) {
//                  $atts = $url;
//                  $url  = $url['href'];
//              } else {
//                  continue;
//              }
//          }
//
//          $url = esc_url( $url, array( 'http', 'https' ) );
//
//          if ( ! $url ) {
//              continue;
//          }
//
//          if ( isset( $unique_urls[ $url ] ) ) {
//              continue;
//          }
//
//          if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) {
//              $parsed = wp_parse_url( $url );
//
//              if ( empty( $parsed['host'] ) ) {
//                  continue;
//              }
//
//              if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) {
//                  $url = $parsed['scheme'] . '://' . $parsed['host'];
//              } else {
//                  // Use protocol-relative URLs for dns-prefetch or if scheme is missing.
//                  $url = '//' . $parsed['host'];
//              }
//          }
//
//          $atts['rel'] = $relation_type;
//          $atts['href'] = $url;
//
//          $unique_urls[ $url ] = $atts;
//      }

  

 

posted @   ytkah  阅读(874)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2017-05-08 群用户通过微信小程序可以更好地协作了
2015-05-08 安卓微信新版内测 可分享小视频/可设微信字体大小
2015-05-08 微信电脑版微信1.1 for Windows更新 可@人/转发撤回消息/可播小视频
2014-05-08 微信 5.3 for iPhone已放出 微信iphone版更新下载
2014-05-08 支付宝也要上"服务号"?斗战微信继续升级
网址导航 gg N / G Sitemap

部分内容来源于网络,如有版权问题请联系删除

  
点击右上角即可分享
微信分享提示