博文中心

WordPress 禁用Emoji表情并自定义表情路径

作者: 分类: 发布于:2019.10.05 阅读:47 次

WordPress 4.2 一改之前的图片表情,改为使用 Emoji 表情 ,而且是直接远程调用api,可惜的是,这个api服务在国内是无法正常访问的,这就导致了网站加载缓慢,之前的表情无法显示等问题。好吧,下面就来禁用这个 Emoji 表情,恢复之前的图片表情。

禁用 Emoji 表情

在主题的 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.
*
* @param array $plugins
* @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce( $plugins ) {
return array_diff( $plugins, array( 'wpemoji' ) );
}

恢复之前的图片表情

在主题的 functions.php 添加代码的代码即可:

function smilies_reset() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( !get_option( 'use_smilies' ) )
return;
$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',
// This one transformation breaks regular text with frequency.
// '8)' => 'icon_cool.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',
);
}
smilies_reset();

使用自定义图片表情

你可以将表情包放在当前主题目录中,然后添加下面的代码到主题的 functions.php 文件中:

function filter_smilies_src($img_src, $img, $siteurl) {
return get_bloginfo('stylesheet_directory') . '/images/smilies/' . $img;
}
add_filter('smilies_src', 'filter_smilies_src', 1, 10);

注意根据自己的实际,修改代码第 2 行的路径,下同。

通过插件自定义WordPress表情

如果在开发插件,需要通过参加自定义WordPress表情路径,可以添加下面的代码到你的插件中:

function filter_smilies_src($img_src, $img, $siteurl) {
return plugins_url('', __FILE__) . '/img/smilies/' . $img;
}
add_filter('smilies_src', 'filter_smilies_src', 1, 10);

修改一下smilies_reset()然后添加下面的代码到主题的 functions.php 文件中:

function smilies_reset() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( !get_option( 'use_smilies' ) )
return;
$wpsmiliestrans = array(
':mrgreen:' => 'mrgreen.png',
':neutral:' => 'neutral.png',
':twisted:' => 'twisted.png',
':arrow:' => 'arrow.png',
':shock:' => 'eek.png',
':smile:' => 'smile.png',
':???:' => 'confused.png',
':cool:' => 'cool.png',
':evil:' => 'evil.png',
':grin:' => 'biggrin.png',
':biggrin:' => 'biggrin.png',
':idea:' => 'idea.png',
':oops:' => 'redface.png',
':redface:' => 'redface.png',
':razz:' => 'razz.png',
':roll:' => 'rolleyes.png',
':rolleyes:' => 'rolleyes.png',
':drooling:' => 'drooling.png',
':cowboy:' => 'cowboy.png',
':persevering:' => 'persevering.png',
':symbols:' => 'symbols.png',
':shit:' => 'shit.png',
':wink:' => 'wink.png',
':cry:' => 'cry.png',
':eek:' => 'eek.png',
':lol:' => 'lol.png',
':mad:' => 'mad.png',
':sad:' => 'sad.png',
'8-)' => 'cool.png',
'8-O' => 'eek.png',
':-(' => 'sad.png',
':-)' => 'smile.png',
':-?' => 'confused.png',
':confused:' => 'confused.png',
':-D' => 'biggrin.png',
':-P' => 'razz.png',
':-o' => 'surprised.png',
':surprised:' => 'surprised.png',
':-x' => 'mad.png',
':-|' => 'neutral.png',
';-)' => 'wink.png',
// This one transformation breaks regular text with frequency.
// '8)' => 'cool.png',
'8O' => 'eek.png',
':(' => 'sad.png',
':)' => 'smile.png',
':?' => 'confused.png',
':D' => 'biggrin.png',
':P' => 'razz.png',
':o' => 'surprised.png',
':x' => 'mad.png',
':|' => 'neutral.png',
';)' => 'wink.png',
':exclaim:' => 'exclaim.png',
':!:' => 'exclaim.png',
':?:' => 'question.png',
);
}
smilies_reset();
1 7
版权声明:
WordPress 禁用Emoji表情并自定义表情路径 _ 引力博客 系本站原创,由 编辑发表 ,转载请注明出处。
本文链接:
我要评论
最新评论
77