VPS测评
主机推荐

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) 打赏
    未经允许不得转载:VPS学院 » WordPress头部去除window._wpemojiSettings代码

    觉得文章有用就打赏一下文章作者

    支付宝扫一扫打赏

    微信扫一扫打赏

    '); })();