下载了最新版的 wordpress4.2,然后搞了一个较新版的主题,主题使用的是国外 emjo 表情包,表情是很不错,但对于不喜欢使用表情评论的童鞋来说,无疑是个累赘,而对于有互联网洁僻的我来说,对于页面源文件加载的一大堆 emjo 表情 js+css 更是觉得很纠心,好了,手动去除开始。,我们有两种解决方法:启用或禁用。,原因分析:脚本就是类似下面的代码:,因为WordPress 更新 4.2 的一个新增功能就是支持 emjo 表情,但看部分加载源居然是 wp.org 的 js 文件。对于大部分人来说,这个是十分鸡肋的功能。,禁用:移除 WordPress 4.2 中前台自动加载的 emoji 脚本,既然功能鸡肋,不如直接移除掉来得更加快捷。代码提取自 Disable Emojis 插件,可以放在主题目录下的 functions.php 文件中:,启用:转存至本地调用 Emoji 表情,WordPress 官方将此功能会写入正式版一定有其理由。但我们知道 WP 的 CDN 早就被*掉,唯一方法就是转存到本地,使 WP 识别本地 Emoji 表情。,Twitter Emoji 表情包下载,下载后直接解压至主题目录,文件夹名不变。将以下代码放在主题目录下的 functions.php 文件中:,好了,我们也可以将国外表情包直接启用在本地的,而我这里直接将其给切除掉了,这样,一切变得安静多了。,
下载了最新版的 wordpress4.2,然后搞了一个较新版的主题,主题使用的是国外 emjo 表情包,表情是很不错,但对于不喜欢使用表情评论的童鞋来说,无疑是个累赘,而对于有互联网洁僻的我来说,对于页面源文件加载的一大堆 emjo 表情 js+css 更是觉得很纠心,好了,手动去除开始。
我们有两种解决方法:启用或禁用。
原因分析:脚本就是类似下面的代码:
因为WordPress 更新 4.2 的一个新增功能就是支持 emjo 表情,但看部分加载源居然是 wp.org 的 js 文件。对于大部分人来说,这个是十分鸡肋的功能。
禁用:移除 WordPress 4.2 中前台自动加载的 emoji 脚本
既然功能鸡肋,不如直接移除掉来得更加快捷。代码提取自 Disable Emojis 插件,可以放在主题目录下的 functions.php 文件中:
- /**
- * Disable the emoji's
- */
- 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_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
- }
- add_action( 'init', 'disable_emojis' );
- /**
- * Filter function used to remove the tinymce emoji plugin.
- */
- function disable_emojis_tinymce( $plugins ) {
- if ( is_array( $plugins ) ) {
- return array_diff( $plugins, array( 'wpemoji' ) );
- } else {
- return array();
- }
- }
启用:转存至本地调用 Emoji 表情
WordPress 官方将此功能会写入正式版一定有其理由。但我们知道 WP 的 CDN 早就被*掉,唯一方法就是转存到本地,使 WP 识别本地 Emoji 表情。
Twitter Emoji 表情包下载,下载后直接解压至主题目录,文件夹名不变。将以下代码放在主题目录下的 functions.php 文件中:
- //首先补全wp的表情库
- function smilies_reset() {
- global $wpsmiliestrans, $wp_smiliessearch;
- // don't bother setting up smilies if they are disabled
- if (!get_option('use_smilies')) {
- return;
- }
- $wpsmiliestrans_fixed = array(
- ':mrgreen:' => "\xf0\x9f\x98\xa2",
- ':smile:' => "\xf0\x9f\x98\xa3",
- ':roll:' => "\xf0\x9f\x98\xa4",
- ':sad:' => "\xf0\x9f\x98\xa6",
- ':arrow:' => "\xf0\x9f\x98\x83",
- ':-(' => "\xf0\x9f\x98\x82",
- ':-)' => "\xf0\x9f\x98\x81",
- ':(' => "\xf0\x9f\x98\xa7",
- ':)' => "\xf0\x9f\x98\xa8",
- ':?:' => "\xf0\x9f\x98\x84",
- ':!:' => "\xf0\x9f\x98\x85",
- );
- $wpsmiliestrans = array_merge($wpsmiliestrans, $wpsmiliestrans_fixed);
- }
- //替换cdn路径
- function static_emoji_url() {
- return get_bloginfo('template_directory').'/72x72/';
- }
- //让文章内容和评论支持 emoji 并禁用 emoji 加载的乱七八糟的脚本
- function reset_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');
- add_filter('the_content', 'wp_staticize_emoji');
- add_filter('comment_text', 'wp_staticize_emoji',50); //在转换为表情后再转为静态图片
- smilies_reset();
- add_filter('emoji_url', 'static_emoji_url');
- }
- add_action('init', 'reset_emojis');
- //输出表情
- function fa_get_wpsmiliestrans(){
- global $wpsmiliestrans;
- $wpsmilies = array_unique($wpsmiliestrans);
- foreach($wpsmilies as $alt => $src_path){
- $emoji = str_replace(array('', ';'), '', wp_encode_emoji($src_path));
- $output .= 'class="add-smily" data-smilies="'.$alt.'">
class="wp-smiley" src="'.get_bloginfo('template_directory').'/72x72/'. $emoji .'png" />';
- }
- return $output;
- }
好了,我们也可以将国外表情包直接启用在本地的,而我这里直接将其给切除掉了,这样,一切变得安静多了。
,
下载了最新版的 wordpress4.2,然后搞了一个较新版的主题,主题使用的是国外 emjo 表情包,表情是很不错,但对于不喜欢使用表情评论的童鞋来说,无疑是个累赘,而对于有互联网洁僻的我来说,对于页面源文件加载的一大堆 emjo 表情 js+css 更是觉得很纠心,好了,手动去除开始。
我们有两种解决方法:启用或禁用。
原因分析:脚本就是类似下面的代码:
因为WordPress 更新 4.2 的一个新增功能就是支持 emjo 表情,但看部分加载源居然是 wp.org 的 js 文件。对于大部分人来说,这个是十分鸡肋的功能。
禁用:移除 WordPress 4.2 中前台自动加载的 emoji 脚本
既然功能鸡肋,不如直接移除掉来得更加快捷。代码提取自 Disable Emojis 插件,可以放在主题目录下的 functions.php 文件中:
- /**
- * Disable the emoji's
- */
- 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_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
- }
- add_action( 'init', 'disable_emojis' );
- /**
- * Filter function used to remove the tinymce emoji plugin.
- */
- function disable_emojis_tinymce( $plugins ) {
- if ( is_array( $plugins ) ) {
- return array_diff( $plugins, array( 'wpemoji' ) );
- } else {
- return array();
- }
- }
启用:转存至本地调用 Emoji 表情
WordPress 官方将此功能会写入正式版一定有其理由。但我们知道 WP 的 CDN 早就被*掉,唯一方法就是转存到本地,使 WP 识别本地 Emoji 表情。
Twitter Emoji 表情包下载,下载后直接解压至主题目录,文件夹名不变。将以下代码放在主题目录下的 functions.php 文件中:
- //首先补全wp的表情库
- function smilies_reset() {
- global $wpsmiliestrans, $wp_smiliessearch;
- // don't bother setting up smilies if they are disabled
- if (!get_option('use_smilies')) {
- return;
- }
- $wpsmiliestrans_fixed = array(
- ':mrgreen:' => "\xf0\x9f\x98\xa2",
- ':smile:' => "\xf0\x9f\x98\xa3",
- ':roll:' => "\xf0\x9f\x98\xa4",
- ':sad:' => "\xf0\x9f\x98\xa6",
- ':arrow:' => "\xf0\x9f\x98\x83",
- ':-(' => "\xf0\x9f\x98\x82",
- ':-)' => "\xf0\x9f\x98\x81",
- ':(' => "\xf0\x9f\x98\xa7",
- ':)' => "\xf0\x9f\x98\xa8",
- ':?:' => "\xf0\x9f\x98\x84",
- ':!:' => "\xf0\x9f\x98\x85",
- );
- $wpsmiliestrans = array_merge($wpsmiliestrans, $wpsmiliestrans_fixed);
- }
- //替换cdn路径
- function static_emoji_url() {
- return get_bloginfo('template_directory').'/72x72/';
- }
- //让文章内容和评论支持 emoji 并禁用 emoji 加载的乱七八糟的脚本
- function reset_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');
- add_filter('the_content', 'wp_staticize_emoji');
- add_filter('comment_text', 'wp_staticize_emoji',50); //在转换为表情后再转为静态图片
- smilies_reset();
- add_filter('emoji_url', 'static_emoji_url');
- }
- add_action('init', 'reset_emojis');
- //输出表情
- function fa_get_wpsmiliestrans(){
- global $wpsmiliestrans;
- $wpsmilies = array_unique($wpsmiliestrans);
- foreach($wpsmilies as $alt => $src_path){
- $emoji = str_replace(array('', ';'), '', wp_encode_emoji($src_path));
- $output .= 'class="add-smily" data-smilies="'.$alt.'">
class="wp-smiley" src="'.get_bloginfo('template_directory').'/72x72/'. $emoji .'png" />';
- }
- return $output;
- }
好了,我们也可以将国外表情包直接启用在本地的,而我这里直接将其给切除掉了,这样,一切变得安静多了。
此处评论已关闭