最新消息:

WordPress表情修复

技术笔记 shanyubawo 1398浏览 0评论

WordPress更新到4.2 ,更新的了emoji表情,但是国内访问不了。之前也改了文件能够使用,但是升级后文件覆盖,又不能用,网上看到几种方法是该主题文件,不用每次升级都要改,记录下。

一,禁用emoji表情

在主题的 functions.php 最底部加入以下代码:

<?php

function disable_emoji_tinymce( $plugins ) {

return array_diff( $plugins, array( 'wpemoji' ) );

}

function remove_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_tinymce' );

}

add_action( 'init', 'remove_emoji' );

?>

二,恢复至原表情模式

在主题的 functions.php 最底部加入以下代码:

<?php

function smilies_initx() {

 global $wpsmiliestrans, $wp_smiliessearch;

 if ( !get_option( 'use_smilies' ) )

 return;

 

 if ( !isset( $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',

 );

 }

 if (count($wpsmiliestrans) == 0) {

 return;

 }

 krsort($wpsmiliestrans);

 $spaces = wp_spaces_regexp();

 $wp_smiliessearch = '/(?<=' . $spaces . '|^)';

 $subchar = '';

 foreach ( (array) $wpsmiliestrans as $smiley => $img ) {

 $firstchar = substr($smiley, 0, 1);

 $rest = substr($smiley, 1);

 if ($firstchar != $subchar) {

 if ($subchar != '') {

 $wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern"

 $wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"

 }

 $subchar = $firstchar;

 $wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';

 } else {

 $wp_smiliessearch .= '|';

 }

 $wp_smiliessearch .= preg_quote($rest, '/');

 }

 $wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';

}

 

remove_action('init', 'smilies_init', 5);

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

?>

使用这种方法比较好,不用升级就要改。

转载请注明:春风博客 » WordPress表情修复

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

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