移除WordPress 4.2 前台自动加载emoji脚本的方法

WordPress 4.2及以上版本,会自动在网站前台加入一段用于支持emjo 表情的脚本(JS+CSS),对于国内大部分站长来说,这个功能是没什么用处的,另外由于(JS+CSS)均托管在国外的服务器上,反而影响网站前台的加载速度。先来认识一下emjo 表情:

emjo 表情符号,来自日语词汇“絵文字”(假名为“えもじ”,读音即emoji),是一套起源于日本的12x12像素表情符号,由栗田穣崇(Shigetaka Kurit)创作,最早在日本网络及手机用户中流行。自苹果公司发布的iOS 5输入法中加入了emoji后,这种表情符号开始席卷全球,目前emoji已被大多数现代计算机系统所兼容的Unicode编码采纳,普遍应用于各种手机短信和社交网络中。文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html

emoji文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html

由于现阶段很多的wordpress站点都不需要这个功能,可以通过以下方法禁用前台自动加载emoji脚本:文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html

将下面禁用前台自动加载emoji脚本的代码放到当前所用主题的function.php文件中。文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html

/*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' );文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html

/**
* Filter function used to remove the tinymce emoji plugin.
* @param array $plugins
* @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html

以上代码来源于disable emojis插件,同样你也可以在wordpress上直接安装disable emojis插件来禁用前台自动加载emoji脚本。文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html 文章源自堕落的鱼-https://www.duoluodeyu.com/1341.html

 
    • perc
      perc 0

      挺好,之前看到那一大段代码,根本不知道是啥,后来才知道是emoji脚本,然后就来到了这里

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
    确定

    拖动滑块以完成验证