当前位置:首页>WordPress建站>网站维护>WordPress 4.2 禁用 Emoji 表情 和修复仪表盘评论头像错位

WordPress 4.2 禁用 Emoji 表情 和修复仪表盘评论头像错位

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

禁用 Emoji 表情

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

  1. /**
  2. * Disabling emoji library from WordPress.
  3. */
  4. function wpkj_disable_emojis() {
  5. // Let's remove a bunch of actions & filters.
  6. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  7. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  8. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  9. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  10. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  11. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  12. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  13. // We also take care of Tiny MCE.
  14. add_filter( 'tiny_mce_plugins', 'wpkj_disable_emojis_tinymce' );
  15. add_filter( 'wp_resource_hints', 'wpkj_disable_emojis_remove_dns_prefetch', 10, 2 );
  16. }
  17. // Let's do this at the init.
  18. add_action( 'init', 'wpkj_disable_emojis' );
  19. /**
  20. * Filter funcion to remove the emoji plugin from TinyMCE.
  21. * @param array $plugins
  22. * @return array Difference betwen the two arrays.
  23. */
  24. function wpkj_disable_emojis_tinymce($plugins) {
  25. if ( is_array( $plugins ) ) {
  26. return array_diff( $plugins, array( 'wpemoji' ) );
  27. } else return array();
  28. }
  29. /**
  30. * Removing emoji CDN hostname from DNS prefetching hints.
  31. * @param array $urls URLs to print for resource hints.
  32. * @param string $relation_type The relation type the URLs are printed for.
  33. * @return array Difference betwen the two arrays.
  34. */
  35. function wpkj_disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
  36. if ( 'dns-prefetch' == $relation_type ) {
  37. /** This filter is documented in wp-includes/formatting.php */
  38. $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
  39. $urls = array_diff( $urls, array( $emoji_svg_url ) );
  40. }
  41. return $urls;
  42. }

恢复之前的图片表情

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

  1. /**
  2. * WordPress 4.2 修复图片表情
  3. * https://www.wpdaxue.com/disable-emoji.html
  4. */
  5. function smilies_reset() {
  6. global $wpsmiliestrans, $wp_smiliessearch;
  7. // don't bother setting up smilies if they are disabled
  8. if ( !get_option( 'use_smilies' ) )
  9. return;
  10. $wpsmiliestrans = array(
  11. ':mrgreen:' => 'icon_mrgreen.gif',
  12. ':neutral:' => 'icon_neutral.gif',
  13. ':twisted:' => 'icon_twisted.gif',
  14. ':arrow:' => 'icon_arrow.gif',
  15. ':shock:' => 'icon_eek.gif',
  16. ':smile:' => 'icon_smile.gif',
  17. ':???:' => 'icon_confused.gif',
  18. ':cool:' => 'icon_cool.gif',
  19. ':evil:' => 'icon_evil.gif',
  20. ':grin:' => 'icon_biggrin.gif',
  21. ':idea:' => 'icon_idea.gif',
  22. ':oops:' => 'icon_redface.gif',
  23. ':razz:' => 'icon_razz.gif',
  24. ':roll:' => 'icon_rolleyes.gif',
  25. ':wink:' => 'icon_wink.gif',
  26. ':cry:' => 'icon_cry.gif',
  27. ':eek:' => 'icon_surprised.gif',
  28. ':lol:' => 'icon_lol.gif',
  29. ':mad:' => 'icon_mad.gif',
  30. ':sad:' => 'icon_sad.gif',
  31. '8-)' => 'icon_cool.gif',
  32. '8-O' => 'icon_eek.gif',
  33. ':-(' => 'icon_sad.gif',
  34. ':-)' => 'icon_smile.gif',
  35. ':-?' => 'icon_confused.gif',
  36. ':-D' => 'icon_biggrin.gif',
  37. ':-P' => 'icon_razz.gif',
  38. ':-o' => 'icon_surprised.gif',
  39. ':-x' => 'icon_mad.gif',
  40. ':-|' => 'icon_neutral.gif',
  41. ';-)' => 'icon_wink.gif',
  42. // This one transformation breaks regular text with frequency.
  43. // '8)' => 'icon_cool.gif',
  44. '8O' => 'icon_eek.gif',
  45. ':(' => 'icon_sad.gif',
  46. ':)' => 'icon_smile.gif',
  47. ':?' => 'icon_confused.gif',
  48. ':D' => 'icon_biggrin.gif',
  49. ':P' => 'icon_razz.gif',
  50. ':o' => 'icon_surprised.gif',
  51. ':x' => 'icon_mad.gif',
  52. ':|' => 'icon_neutral.gif',
  53. ';)' => 'icon_wink.gif',
  54. ':!:' => 'icon_exclaim.gif',
  55. ':?:' => 'icon_question.gif',
  56. );
  57. }
  58. smilies_reset();

以上2处代码来自:http://fatesinger.com/75634

解决仪表盘头像错位

WordPress 4.2 开始,仪表盘的“活动”小工具的头像就出现撑破现象,如下图:

2015-05-16_111011_wpdaxue_com

一直没见官方修复,好吧,倡萌就提供暂时的修复方案吧。将下面的代码添加到主题的 functions.php :

  1. /**
  2. * WordPress 4.2 修复仪表盘头像错位
  3. * https://www.wpdaxue.com/disable-emoji.html
  4. */
  5. function fixed_activity_widget_avatar_style(){
  6. echo '<style type="text/css">
  7. #activity-widget #the-comment-list .avatar {
  8. position: absolute;
  9. top: 13px;
  10. width: 50px;
  11. height: 50px;
  12. }
  13. </style>';
  14. }
  15. add_action('admin_head', 'fixed_activity_widget_avatar_style' );

刷新你的仪表盘,看看是否OK啦!相信官方会在后续修复这个问题的,到时就不需要这个代码了。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
欢迎关注WordPress大学公众号 WPDAXUE
网站维护

解决万网主机下 WordPress 无法发送邮件的问题

2015-5-16 10:57:46

网站维护

WordPress网站优化插件youpzt-optimizer,给网站提速70%

2015-6-21 12:12:38

4 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
  1. 貌似都没有怎么使用过任何表情的路过,然后就直接把emoji表情禁用了。

  2. 😛 更新了,还是可以。

  3. 还没有更新,主题还在用3.9的

  4. 头像出现大小错误是因为新增了srcset属性,原来替换服务器那个函数有问题,我已经更新了代码http://fatesinger.com/74030 😈

个人中心
购物车
优惠劵
今日签到
私信列表
搜索