移除WordPress4.2中用Emoji表情并替换自定义表情

今早给wordpress升了个级,然后头像表情都不显示了,WordPress4.2中使用了Emoji表情,但是我并不想要这个表情。╮( ̄▽ ̄”)╭ 首先解决下表情问题:
关闭颜文字的代码:

function disable_emoji9s_tinymce( $plugins ) {
	if ( is_array( $plugins ) ) {
		return array_diff( $plugins, array( 'wpemoji' ) );
	} else {
		return array();
	}
}

function remove_emoji9s() {
	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_action( 'init', 'remove_emoji9s' );

加载WordPress4.2版本之前的主题默认表情

打开WordPress4.12根目录下wp-includes\functions.php第2755行对比WordPress4.2根目录下wp-includes\functions.php第2946行,吐槽:坑,注释不变版本号不变,这函数咋变了?如果需要WordPress4.2正常使用主题自带的默认表情怎么办?
复制代码如下:

function disable_emoji9s_tinymce( $plugins ) {
	if ( is_array( $plugins ) ) {
		return array_diff( $plugins, array( 'wpemoji' ) );
	} else {
		return array();
	}
}

//取当前主题下img\smilies\下表情图片路径
function custom_smilie9s_src( $old, $img ) {
    return get_stylesheet_directory_uri().'/img/smilies/'.$img;
}

function init_smilie9s(){
	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',
	);
	//移除WordPress4.2版本更新所带来的Emoji钩子同时挂上主题自带的表情路径
	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_smilie9s_src' , 10 , 2 );
}

add_action( 'init', 'init_smilie9s', 5 );

使用方法:复制粘贴到当前主题的functions.php文件末尾,有使用缓存的刷新一下缓存即可。移除了wp-includes\default-filters.php中颜文字(Emoji)加载所需的JS、CSS以及恶心无耻默认集成到wp_mail函数的等等钩子,同时添加了一个钩子把Tinymce编辑器中的颜文字也搞(替换)掉。本方法摘自:http://www.9sep.org/remove-emoji-in-wordpress

本文共 14 个回复

  1. 之行 says:
    升级后主题崩了´▽`已抛弃wp
  2. Meekdai says:
    额,我那里的颜文字就不错呀!
    1. 小二苘 PO主 says:
      @Meekdai 原来你说的是这个呀,我更新后咋没看到有这个表情呢╮( ̄▽ ̄")╭
  3. 破小懿 says:
    唉,主题挂了两天,没电脑,只能干瞪眼,然后作者改了才用上,真纠结,我也想换掉wp了 :cry:
  4. 星光 says:
    好赞,我正好也遇到这个问题了,O(∩_∩)O谢谢

发表留言,喵!