WordPress 教程:WordPress 4.2后 头部多出的Emoji表情的处理方法
如果你更新到 WordPress 的 4.2 版本,查看网页源代码你会发现 WordPress 会自动在加载一…
如果你更新到 WordPress 的 4.2 版本,查看网页源代码你会发现 WordPress 会自动在加载一段用于支持 emjo 表情的脚本(JS+CSS)。对于大部分人来说,这个是十分鸡肋的功能,再加上 GFW 的强大力量,反而影响加载速度。
我们有两种解决方法:启用或禁用。
原因分析
脚本就是类似下面的代码:
- <script type=“text/javascript”>
- “baseUrl”:“http://s.w.org/images/core/emoji/72×72/”,“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”,
-
“xf0x9fx98xa6”,
- ‘:arrow:’ => “xf0x9fx98x83”,
-
“xf0x9fx98x82”,
- ‘:-)’ => “xf0x9fx98x81”,
-
“xf0x9fx98xa7”,
- ‘:)’ => “xf0x9fx98xa8”,
-
“xf0x9fx98x84”,
- ‘:!:’ => “xf0x9fx98x85”,
- $wpsmiliestrans = array_merge($wpsmiliestrans, $wpsmiliestrans_fixed);
- function static_emoji_url() {
- return get_bloginfo(‘template_directory’).’/72×72/’;
- 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’).’/72×72/’. $emoji .’png” /></a>’;
- return $output;
- }
类别:WordPress经验、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!