WordPress4.2以降のバージョンでは、自動で絵文字を表示するためのコードが出力されるようになっています。
しかし絵文字を使用している人は少なく、コードが煩雑になってしまい、ページの表示速度が遅くなる原因にもなってしまいます。
そこで、絵文字を使用していない人は絵文字を無効化してコードをすっきりさせておきましょう。
WordPressの絵文字とは
WordPressは、バージョン4.2から絵文字が利用できるようになり、下記のコードが出力されるようになりました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <script type="text/javascript"> window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/11\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/11\/svg\/","svgExt":".svg","source":{"concatemoji":"http:\/\/mytestsite.local\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.0.3"}}; !function(a,b,c){function d(a,b){var c=String.fromCharCode;l.clearRect(0,0,k.width,k.height),l.fillText(c.apply(this,a),0,0);var d=k.toDataURL();l.clearRect(0,0,k.width,k.height),l.fillText(c.apply(this,b),0,0);var e=k.toDataURL();return d===e}function e(a){var b;if(!l||!l.fillText)return!1;switch(l.textBaseline="top",l.font="600 32px Arial",a){case"flag":return!(b=d([55356,56826,55356,56819],[55356,56826,8203,55356,56819]))&&(b=d([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]),!b);case"emoji":return b=d([55358,56760,9792,65039],[55358,56760,8203,9792,65039]),!b}return!1}function f(a){var c=b.createElement("script");c.src=a,c.defer=c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var g,h,i,j,k=b.createElement("canvas"),l=k.getContext&&k.getContext("2d");for(j=Array("flag","emoji"),c.supports={everything:!0,everythingExceptFlag:!0},i=0;i<j.length;i++)c.supports[j[i]]=e(j[i]),c.supports.everything=c.supports.everything&&c.supports[j[i]],"flag"!==j[i]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&c.supports[j[i]]);c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.everything||(h=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",h,!1),a.addEventListener("load",h,!1)):(a.attachEvent("onload",h),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),g=c.source||{},g.concatemoji?f(g.concatemoji):g.wpemoji&&g.twemoji&&(f(g.twemoji),f(g.wpemoji)))}(window,document,window._wpemojiSettings); </script> <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> |
しかし、絵文字を使用していない人にとっては余計なコードでしかなく、ページの表示速度にも影響してしまいます。
そこで、絵文字用のスクリプトが出力されないように設定を変更してしまいましょう。
絵文字を無効化する方法
WordPressの絵文字を無効化する方法は、大きく分けて下記の2つの方法があります。
- テーマを編集する
- プラグインを利用する
初心者の方はプラグインを利用する方法が簡単で安全なのでおすすめです。余計なプラグインを追加したくないという方は、テーマを編集して絵文字を無効化しましょう。
テーマを編集して絵文字を無効化する方法
WordPressの絵文字を無効化する方法は簡単で、下記のコードをfunctions.php
に追加するだけです。
1 2 3 4 5 6 7 8 9 10 | function disable_emojis() { 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_action( 'init', 'disable_emojis' ); |
プラグインを追加して絵文字を無効化する方法
テーマを編集したくない!という場合はプラグインを追加して絵文字を無効化することも可能です。
「Disable Emojis」というプラグインを追加すれば、絵文字用のスクリプトが出力されなくなります。