修復WordPress4.2更新后主題表情不顯示

加載WordPress4.2版本之前的主題默認表情補丁

wordpress更新至4.2后,文章、評論中的表情無法顯示?

解決辦法·使用WordPress4.2 Emoji補丁代碼如下,加入到你wordpress主題目錄的functions.php文件中,放最后就行:

  1. <?php
  2. function?smilies_initx()?{
  3. ?global?$wpsmiliestrans,?$wp_smiliessearch;
  4. ?if?(?!get_option(?'use_smilies'?)?)
  5. ?return;
  6. ?if?(?!isset(?$wpsmiliestrans?)?)?{
  7. ?$wpsmiliestrans?=?array(
  8. ?':mrgreen:'?=>?'icon_mrgreen.gif',
  9. ?':neutral:'?=>?'icon_neutral.gif',
  10. ?':twisted:'?=>?'icon_twisted.gif',
  11. ?':arrow:'?=>?'icon_arrow.gif',
  12. ?':shock:'?=>?'icon_eek.gif',
  13. ?':smile:'?=>?'icon_smile.gif',
  14. ?':???:'?=>?'icon_confused.gif',
  15. ?':cool:'?=>?'icon_cool.gif',
  16. ?':evil:'?=>?'icon_evil.gif',
  17. ?':grin:'?=>?'icon_biggrin.gif',
  18. ?':idea:'?=>?'icon_idea.gif',
  19. ?':oops:'?=>?'icon_redface.gif',
  20. ?':razz:'?=>?'icon_razz.gif',
  21. ?':roll:'?=>?'icon_rolleyes.gif',
  22. ?':wink:'?=>?'icon_wink.gif',
  23. ?':cry:'?=>?'icon_cry.gif',
  24. ?':eek:'?=>?'icon_surprised.gif',
  25. ?':lol:'?=>?'icon_lol.gif',
  26. ?':mad:'?=>?'icon_mad.gif',
  27. ?':sad:'?=>?'icon_sad.gif',
  28. ?'8-)'?=>?'icon_cool.gif',
  29. ?'8-O'?=>?'icon_eek.gif',
  30. ?':-('?=>?'icon_sad.gif',
  31. ?':-)'?=>?'icon_smile.gif',
  32. ?':-?'?=>?'icon_confused.gif',
  33. ?':-D'?=>?'icon_biggrin.gif',
  34. ?':-P'?=>?'icon_razz.gif',
  35. ?':-o'?=>?'icon_surprised.gif',
  36. ?':-x'?=>?'icon_mad.gif',
  37. ?':-|'?=>?'icon_neutral.gif',
  38. ?';-)'?=>?'icon_wink.gif',
  39. ?'8O'?=>?'icon_eek.gif',
  40. ?':('?=>?'icon_sad.gif',
  41. ?':)'?=>?'icon_smile.gif',
  42. ?':?'?=>?'icon_confused.gif',
  43. ?':D'?=>?'icon_biggrin.gif',
  44. ?':P'?=>?'icon_razz.gif',
  45. ?':o'?=>?'icon_surprised.gif',
  46. ?':x'?=>?'icon_mad.gif',
  47. ?':|'?=>?'icon_neutral.gif',
  48. ?';)'?=>?'icon_wink.gif',
  49. ?':!:'?=>?'icon_exclaim.gif',
  50. ?':?:'?=>?'icon_question.gif',
  51. ?);
  52. ?}
  53. ?if?(count($wpsmiliestrans)?==?0)?{
  54. ?return;
  55. ?}
  56. ?krsort($wpsmiliestrans);
  57. ?$spaces?=?wp_spaces_regexp();
  58. ?$wp_smiliessearch?=?'/(?<='?.?$spaces?.?'|^)';
  59. ?$subchar?=?'';
  60. ?foreach?(?(array)?$wpsmiliestrans?as?$smiley?=>?$img?)?{
  61. ?$firstchar?=?substr($smiley,?0,?1);
  62. ?$rest?=?substr($smiley,?1);
  63. ?if?($firstchar?!=?$subchar)?{
  64. ?if?($subchar?!=?'')?{
  65. ?$wp_smiliessearch?.=?')(?='?.?$spaces?.?'|$)';?//?End?previous?"subpattern"
  66. ?$wp_smiliessearch?.=?'|(?<='?.?$spaces?.?'|^)';?//?Begin?another?"subpattern"
  67. ?}
  68. ?$subchar?=?$firstchar;
  69. ?$wp_smiliessearch?.=?preg_quote($firstchar,?'/')?.?'(?:';
  70. ?}?else?{
  71. ?$wp_smiliessearch?.=?'|';
  72. ?}
  73. ?$wp_smiliessearch?.=?preg_quote($rest,?'/');
  74. ?}
  75. ?$wp_smiliessearch?.=?')(?='?.?$spaces?.?'|$)/m';
  76. }
  77. remove_action('init',?'smilies_init',?5);
  78. add_action(?'init'?,?'smilies_initx'?,?5?);
  79. ?>

關于恢復自定義表情后樣式變小的解決辦法

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行

  1. <!--<style?type="text/css">
  2. img.wp-smiley,
  3. img.emoji?{
  4. ????display:?inline?!important;
  5. ????border:?none?!important;
  6. ????box-shadow:?none?!important;
  7. ????height:?1em?!important;
  8. ????width:?1em?!important;
  9. ????margin:?0?.07em?!important;
  10. ????vertical-align:?-0.1em?!important;
  11. ????background:?none?!important;
  12. ????padding:?0?!important;
  13. }
  14. </style>-->

2、在找到你主題的css文件,style.css,加入以下代碼

  1. .wp-smiley{height:?100%?!important;max-height:?100%?!important;}

發表評論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前評論:1   其中:訪客  1   博主  0

  1. avatar Han 1

    不錯的方法,已經用上了