首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >禁止/移除 WordPress 4.2 中前台自动加载的 emjo 脚本

禁止/移除 WordPress 4.2 中前台自动加载的 emjo 脚本

作者头像
Jeff
发布2018-01-22 10:39:32
9950
发布2018-01-22 10:39:32
举报
文章被收录于专栏:DeveWorkDeveWork

如果你更新了WordPress 最新版本的4.2 版本,查看网页源代码你会发现WordPress 会自动在head加载一段用于支持emjo 表情的脚本(JS+CSS),对于大部分人来说,这个是十分鸡肋的功能,反而影响加载速度。

原因分析

脚本就是类似下面的代码:

<script type="text/javascript"> window._wpemojiSettings = {"baseUrl":"http:\/\/s.w.org\/images\/core\/emoji\/72x72\/","ext":".png","source":{"concatemoji":"http:\/\/devework.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.2"}}; !function(a,b,c){function d(a){var c=b.createElement("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f;c.supports={simple:d("simple"),flag:d("flag")},c.supports.simple&&c.supports.flag||(f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings); </script> <style type="text/css"> img.wp-smiley, img.emoji { display: inline !important; border: none !important; box-shadow: none !important; height: 1em !important; width: 1em !important; margin: 0 .07em !important; vertical-align: -0.1em !important; background: none !important; padding: 0 !important; } </style>

代码就不过多解读了。因为WordPress 更新4.2 的一个新增功能就是支持emjo 表情,但看部分加载源居然是wp.org的js 文件(wp.org 有被墙否?)对于大部分人来说,这个是十分鸡肋的功能。

去除/删除/禁止方法

要禁止WordPress 在前台自动加载这段脚本,可以用以下方法:

1)插件法

安装 Disable Emojis 插件:https://wordpress.org/plugins/disable-emojis/

2)代码法

直接添加下面的代码到主题的functions.php 文件,代码其实就是来源上面的插件:

/** * Disable the emoji's */ function disable_emojis() { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'admin_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' ); add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' ); } add_action( 'init', 'disable_emojis' );   /** * Filter function used to remove the tinymce emoji plugin. */ function disable_emojis_tinymce( $plugins ) { return array_diff( $plugins, array( 'wpemoji' ) ); }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015/04/24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 原因分析
  • 去除/删除/禁止方法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档