如何禁止WordPress頭部加載s.w.org

下面由WordPress教程欄目給大家介紹禁止wordpress頭部加載s.w.org的方法,希望對需要的朋友有所幫助!

如何禁止WordPress頭部加載s.w.org

摘要

WordPress在頭部添加dns-prefetch,應(yīng)該是為了從s.w.org預(yù)獲取表情和頭像,目的是提高網(wǎng)頁加載速度 ,但s.w.org國內(nèi)根本無法訪問,什么預(yù)獲取、什么提高速度,都是泡影,不僅沒用處,反而可能會影響速度,那就禁止它。

禁止WordPress頭部加載s.w.org

升級到WordPress 4.6之后,有童鞋發(fā)現(xiàn)頭部加載了一個:

<link>

WordPress在頭部添加dns-prefetch,應(yīng)該是為了從s.w.org預(yù)獲取表情和頭像,目的是提高網(wǎng)頁加載速度 ,但s.w.org國內(nèi)根本無法訪問,什么預(yù)獲取、什么提高速度,都是泡影,不僅沒用處,反而可能會影響速度,那就禁止它。

將下面的代碼添加到主題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教程

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊7 分享