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; // } |

加微信交流
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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 支付宝也要上"服务号"?斗战微信继续升级