加载WordPress4.2版本之前的主题默认表情补丁
wordpress更新至4.2后,文章、评论中的表情无法显示?
解决办法·使用WordPress4.2 Emoji补丁代码如下,加入到你wordpress主题目录的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 );
- ?>
关于恢复自定义表情后样式变小的解决办法
WordPress4.2版本wp-includes\formatting.php文件第2085行的translate_smiley函数。在注解/版本号基本(只是4.2版本注解少了两个单引号而已)没变的情况下强行(这货函数没有直接提供钩子)为表情加了element.style{height: 1em; max-height: 1em;}这感觉就是不给使用多年的默认表情一点活路死命要推广颜文字的节奏。
解决办法:
1、打开wp-includes\formatting.php文件,搜索 img.wp-smiley 将以下部分注释,大致在4322行
- <!–<style type=“text/css”>
- img.wp-smiley,
- img.emoji {
- display: inline !important;
- border: none !important;
- box-shadow: none !important;
- height: 1em !important;
- width: 1em !important;
- margin: 0 .07em !important;
- vertical-align: -0.1em !important;
- background: none !important;
- padding: 0 !important;
- }
- </style>–>
2、在找到你主题的css文件,style.css,加入以下代码
- .wp-smiley{height: 100% !important;max-height: 100% !important;}
原创文章,作者:wwh,如若转载,请注明出处:https://www.wuwenhui.cn/3600.html
评论列表(2条)
不错的方法,已经用上了
测试一下。我的也不显示了 :razz: