欢迎来到模板无忧!织梦模板,dede模板下载,织梦cms模板,免费网站模板下载站

模板无忧

禁止/移除WordPress4.2中前台自动加载的emjo脚本

企业模板

禁止/移除WordPress4.2中前台自动加载的emjo脚本

假如你更新了WordPress 最新版本的4.2 版本,查询网页源码你会发现WordPress 会自动在加载一段用于支持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.getContextc.getContext("2d");return dd.fillText?(d.textBaseline="TOP",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length3e3):(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.simplec.supports.flag||(f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemojif.twemoji(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);/scriptstyle 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' ) );}

声明:

本文章转自:DeveWork (转载此文章仅为学习交流只用,如有异议请联系本站删除,谢谢!)


希望以上内容可以解决您的问题!
如有其他问题欢迎大家一起交流学习!
作者:模板无忧 来源:互联网 关注: 时间:2021-04-27 17:25
版权声明:凡注明来源为http://www.nsxcb.cn的均为本站原创,转载请注明来源。
本文网址:http://www.nsxcb.cn/wordpress/jiaocheng/20210427/12208.html
►凡本站提供教程均已验证教程的准确性。
►为提高用户在织梦后台添加栏目的灵活性(可随意添加/删除栏目),并保持(管理后台添加/删除栏目)与前端网站栏目的一致,本站模板中栏目均未固定,用户直接搜索typeid=''并替换''中的数字为所需栏目id即可。
►本站提供各种类型织梦模板!希望在这里找到喜欢的。下载本站模板,用户直接替换相关文字和图片即可。
►本站仅提供织梦模板即(DEDE模板),(除另外说明)均不带织梦安装程序及数据,用户直接覆盖默认模板即可。
►本站所有资源(包括源码、模板、插件等)仅供学习与参考,请勿用于商业用途。
►如有其他问题,请加网站客服QQ(375750496)进行交流。
相关织梦教程
在线客服

织梦模板 整站模板 新手教程 使用技巧