欢迎光临
我们一直在努力
卡尔云 大网数据--高防低价服务器抢购 低至28/月十堰4-4就在零零陆云计算 金华高防物理机 40H64G 30M 158/月 819云计算香港20MCN2 300元/月
林枫云-专注独立IP高频VPS 低价高性价比—迅速云 GoDo云计算韩国物理机低至299元/月 龍行数据:美国100M服务器 299元/月 络V云计算:新加坡100M服务器 1200元/月
CNMCDN防护稳定又实惠 轻松云:美国200兆VPS16元/月 亦宁云200M大带宽 动态BGP低至35/月 低价高效上云-道之云网络 【科御云】香港CDN、延迟低速度快防御高

WordPress头部去除window._wpemojiSettings代码

最近对部落的wordpress版本进行了升级,懒癌患者加上技术盲,之前还一直在使用wordpress3.9,升级到最新wordpress之后,在查看网页源代码的时候发现,头部多了一长串乱七八糟的代码,查了下貌似是表情加载之类的,对我没有什么用,而且看起来很不舒服,所以把它去掉。

图截得小了,不好意思……反正这一篇都是,通过网上搜索的方法,在主题的functions.php文件中加入如下代码即可:

/**去除window._wpemojiSettings**/remove_action( \\\'admin_print_scripts\\\', \\\'print_emoji_detection_script\\\');remove_action( \\\'admin_print_styles\\\', \\\'print_emoji_styles\\\');remove_action( \\\'wp_head\\\', \\\'print_emoji_detection_script\\\', 7);remove_action( \\\'wp_print_styles\\\', \\\'print_emoji_styles\\\');remove_filter( \\\'the_content_feed\\\', \\\'wp_staticize_emoji\\\');remove_filter( \\\'comment_text_rss\\\', \\\'wp_staticize_emoji\\\');remove_filter( \\\'wp_mail\\\', \\\'wp_staticize_emoji_for_email\\\');

在处理这个问题的时候,无意中看到有人提到另一个问题,查看网页源码中有下面这句:

link rel=\\\'dns-prefetch\\\' href=\\\'//s.w.org\\\';

在头部添加了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 );

据说第二种兼容性更好,不过我就用的第一种也能用。

本文所涉及代码及方法来源于网络

赞(0)
未经允许不得转载:沃园 » WordPress头部去除window._wpemojiSettings代码

评论 抢沙发

评论前必须登录!

立即登录   注册