如果你更新到 WordPress 的 4.2 版本,檢視網頁原始碼你會發現 WordPress 會自動在載入一段用於支援 emjo 表情的指令碼 (JS+CSS) 。對於大部分人來說,這個是十分雞肋的功能,再加上 GFW 的強大力量,反而影響載入速度。
我們有兩種解決方法:啟用或停用。
原因分析
指令碼就是類似下面的程式碼:
- <script type="text/javascript">
- "baseUrl":"http://s.w.org/images/core/emoji/72x72/","ext":".png","source":{"concatemoji":"http://devework.com/wp-includes/js/wp-emoji-release.min.js?ver=4.2"}};
- !function(a,b,c){function d(a){var c=b.createElement("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f;c.supports={simple:d("simple"),flag:d("flag")},c.supports.simple&&c.supports.flag||(f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
- <style type="text/css">
- img.emoji {
- border: none !important;
- height: 1em !important;
- margin: 0 .07em !important;
- background: none !important;
- }
- functions.php 檔案中:
- function disable_emojis() {
- remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
- remove_action( 'wp_print_styles', 'print_emoji_styles' );
- remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
- remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
- }
- function disable_emojis_tinymce( $plugins ) {
- if ( is_array( $plugins ) ) {
- return array_diff( $plugins, array( 'wpemoji' ) );
- } else {
- return array();
- }
- Twitter Emoji 表情包下載,下載後直接解壓至主題目錄,資料夾名不變。將以下程式碼放在主題目錄下的 functions.php 檔案中:
- function smilies_reset() {
- global $wpsmiliestrans, $wp_smiliessearch;
- if (!get_option('use_smilies')) {
- return;
- }
- $wpsmiliestrans_fixed = array(
- ':mrgreen:' => "xf0x9fx98xa2",
"xf0x9fx98xa3",
- ':roll:' => "xf0x9fx98xa4",
- ':arrow:' => "xf0x9fx98x83",
- ':-)' => "xf0x9fx98x81",
- ':)' => "xf0x9fx98xa8",
- ':!:' => "xf0x9fx98x85",
- $wpsmiliestrans = array_merge($wpsmiliestrans, $wpsmiliestrans_fixed);
- function static_emoji_url() {
- return get_bloginfo('template_directory').'/72x72/';
- function reset_emojis() {
- remove_action('wp_head', 'print_emoji_detection_script', 7);
- remove_action('wp_print_styles', 'print_emoji_styles');
- add_filter('the_content', 'wp_staticize_emoji');
- smilies_reset();
- }
- function fa_get_wpsmiliestrans(){
- global $wpsmiliestrans;
- $wpsmilies = array_unique($wpsmiliestrans);
- foreach($wpsmilies as $alt => $src_path){
- $emoji = str_replace(array('&#x', ';'), '', wp_encode_emoji($src_path));
- $output .= '<a class="add-smily" data-smilies="'.$alt.'"><img class="wp-smiley" src="'.get_bloginfo('template_directory').'/72x72/'. $emoji .'png" /></a>';
- return $output;
- }
"xf0x9fx98xa6",
"xf0x9fx98x82",
"xf0x9fx98xa7",
"xf0x9fx98x84",