最近在一个主题上面发现自定义表情路径都跳转到s.w.org,均无法显示,估计是被墙了,网上找了一下解决方案,
原来wordpress从4.2开始添加了emoji表情,而由于大陆的网络环境(你们懂得),导致标签无法加载完成,于是赶紧找办法,把在线表情替换为本地的表情,在这里附上解决方案。
把下面的代码添加到主题的 function.php即可
//4.2表情修正
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' );
function custom_smilie9s_src( $old, $img ) {
return get_stylesheet_directory_uri().'/images/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 );
//取消添加表情样式
function disable_emojis_tinymce( $plugins ) {
return array_diff( $plugins, array( 'wpemoji' ) );
}
文章来源于网络或者作者投稿,若有侵权请联系删除,作者:老钟,如若转载,请注明出处:https://www.laoz.net/798.html