国内外主机
测评及优惠码

如何才能禁止WordPress头部加载s.w.org?

WordPress在头部添加dnsprefetch,应该是为了从s.w.org获取表情和头像,目的是提高网页加载速度 ,但s.w.org国内根本无法访问,什么预获取、什么提高速度,都是泡影,不仅没用处,反而可能会影响速度,那就禁止它。如何才能禁止如何才能禁止WordPress头部加载s.w.org?加载s.w.org?

 

升级到WordPress 4.6之后,发现头部加载了一个:

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

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' );

方法二

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头部加载s.w.org的详细内容。

赞一个
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《如何才能禁止WordPress头部加载s.w.org?》
文章链接:https://www.ibytx.com/2004.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

登录

找回密码

注册