wordpress评论 默认是不支持表情的,有很多插件可以实现,这里手动DIY来添加这个功能,使用我们自己喜欢的gif文件替换WP自带的,从而本地化。
1、加载emoji表情路径文件
在评论页面(comments.PHP)合适的位置,引入smiley.PHP文件
PHP include(TEMPLATEPATH . '/smiley.PHP'); ?>
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_question.gif" title="疑问" alt="疑问" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_razz.gif" title="抓狂" alt="抓狂" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_sad.gif" title="汗" alt="汗" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_evil.gif" title="委屈" alt="委屈" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_exclaim.gif" title="鄙视" alt="鄙视" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_smile.gif" title="微笑" alt="微笑" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_redface.gif" title="可爱" alt="可爱" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_biggrin.gif" title="坏笑" alt="坏笑" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_surprised.gif" title="吃惊" alt="吃惊" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_eek.gif" title="狂晕" alt="狂晕" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_confused.gif" title="可怜" alt="可怜" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_cool.gif" title="酷" alt="酷" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_lol.gif" title="奸" alt="奸" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_mad.gif" title="怒" alt="怒" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_twisted.gif" title="狂" alt="狂" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_rolleyes.gif" title="馋" alt="馋" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_wink.gif" title="调皮" alt="调皮" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_idea.gif" title="色" alt="色" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_arrow.gif" title="囧" alt="囧" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_neutral.gif" title="偷笑" alt="偷笑" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_cry.gif" title="哭" alt="哭" />
PHP echo get_template_directory_uri(); ?>/images/smilies/icon_mrgreen.gif" title="嘿" alt="嘿" />
2、下载emoji表情包
很明显上面的文件我把emoji表情包/images/smilies/下面
百度网盘下载:http://pan.baidu.com/s/1c1NQyis
3、修复表情包引入
wordpress4.2之后,使用了Emoji表情,原有自定义表情快捷符号无法再转换为表情图片gif,而我们引入的是gif文件,这样并不会显示的,所以需要禁用前台与后台的相关emoji表情加载脚本,并修改css文件调整大小。加入以下代码至主题的functions.PHP内:
/**
* 替换emjo表情修复wordpress升级4.2自定义表情的各种问题
*/
function disable_emoji($plugins) {
if (is_array($plugins)) {
return array_diff($plugins,array(
'wpemoji'
));
} else {
return array();
}
}
function custom_smilie_src($old,$img) {
return get_stylesheet_directory_uri() . '/images/smilies/' . $img;
}
function init_fixsmilie() {
global $wpsmiliestrans;
add_filter('smilies_src','fa_smilies_src',1,10);
$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_emoji');
add_filter('smilies_src','custom_smilie_src',10,2);
}
add_action('init','init_fixsmilie',5);
这样你可以灵活的DIY,替换增加你喜欢的表情图标,文件的路径等等,轻松实现了wordpress评论插件表情功能,已经在wordpress4.7经过测试。