欢迎光临
我们一直在努力

wordpress如何禁止加载s.w.org (emoji)

这个问题是因为WordPress4.2版本更新之后官方决定加载第三方emoji表情,但是其“卓越”的代码行为规范以及WordPress不顾zh_CN版本庞大的用户群体(也许还有别的心思),强制启用Emoji引起了国内外各种主题的异常,表情异常,后台文章可视化编辑器打开超级慢等等情况;严重伤害了伪处女座强迫症患者的心(当然知晓代码规范去看了WordPress4.2+更新的几个文件也会认同这点:糟糕·透叻!),怎么修复这些问题呢?移除WordPress4.2以及之后版本中颜文字(Emoji)加载所需的JS、CSS以及恶心无耻默认集成到wp_mail函数(邮件回复也就自动加载看不到的Emoji,只见奇葩的四字节编码,破坏了原来辛辛苦苦设计的邮件回复样式不会火,我相信你!)的等等钩子,同时添加了一个钩子把文章可视化(Tinymce)编辑器中的要加载的第三方颜文字也搞(替换)掉。拒绝被强迫,从我做起!
以下代码加入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 ) {
    if ( is_array( $plugins ) ) {
        return array_diff( $plugins, array( 'wpemoji' ) );
    } else {
        return array();
    }
}

或者

/**
 * Disable the emoji's
 */
function disable_emoji9s_tinymce($plugins) { if (is_array($plugins)) { return array_diff($plugins, array( 'wpemoji' )); } else { return array(); }}
function custom_gitsmilie_src($old, $img) { return get_stylesheet_directory_uri() . '/img/smilies/' . $img;}
function init_gitsmilie() { global $wpsmiliestrans; $wpsmiliestrans = array(
	':mrgreen:' => 'icon_mrgreen.gif',
	':neutral:' => 'icon_neutral.gif',
	':twisted:' => 'icon_twisted.gif',
	':arrow:' => 'icon_arrow.gif',
	':shock:' => 'icon_eek.gif',
	':smile:' => 'icon_smile.gif',
	':???:' => 'icon_confused.gif',
	':cool:' => 'icon_cool.gif',
	':evil:' => 'icon_evil.gif',
	':grin:' => 'icon_biggrin.gif',
	':idea:' => 'icon_idea.gif',
	':oops:' => 'icon_redface.gif',
	':razz:' => 'icon_razz.gif',
	':roll:' => 'icon_rolleyes.gif',
	':wink:' => 'icon_wink.gif',
	':cry:' => 'icon_cry.gif',
	':eek:' => 'icon_surprised.gif',
	':lol:' => 'icon_lol.gif',
	':mad:' => 'icon_mad.gif',
	':sad:' => 'icon_sad.gif',
	'8-)' => 'icon_cool.gif',
	'8-O' => 'icon_eek.gif',
	':-(' => 'icon_sad.gif',
	':-)' => 'icon_smile.gif',
	':-?' => 'icon_confused.gif',
	':-D' => 'icon_biggrin.gif',
	':-P' => 'icon_razz.gif',
	':-o' => 'icon_surprised.gif',
	':-x' => 'icon_mad.gif',
	':-|' => 'icon_neutral.gif',
	';-)' => 'icon_wink.gif',
	'8O' => 'icon_eek.gif',
	':(' => 'icon_sad.gif',
	':)' => 'icon_smile.gif',
	':?' => 'icon_confused.gif',
	':D' => 'icon_biggrin.gif',
	':P' => 'icon_razz.gif',
	':o' => 'icon_surprised.gif',
	':x' => 'icon_mad.gif',
	':|' => 'icon_neutral.gif',
	';)' => 'icon_wink.gif',
	':!:' => 'icon_exclaim.gif',
	':?:' => 'icon_question.gif',);
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_emoji9s_tinymce');
add_filter('smilies_src', 'custom_gitsmilie_src', 10, 2);}
add_action('init', 'init_gitsmilie', 5);

 

赞(0)
版权归原作者所有,如有侵权请告知。达维营-前端网 » wordpress如何禁止加载s.w.org (emoji)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址