WordPress禁用Emoji表情及本地化Emoji提高网站速度
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

对于普通的个人博客、网站应用WordPress程序其实已经足够使用,但是因为官方的维护和不断的完善,在添加和修正安全的同时,也会增加一些其他的升级元素。这就使得我们在使用WordPress的时候会发现即便程序是非常完美的,目前也没有其他多么优秀的CMS可以替代,唯独就是比较臃肿,甚至会加载一些外部的调用。
尤其使得我们国内的用户访问比较慢,比如在WordPress4.2版本之后,增加了Emoji表情外部调用,大部分用户是使用不到的,我们如果认为也没有必要,可以依据下面的方法之一去掉或者替换本地加载。
第一、检查是否有Emoji表情
如果我们查看源文件,可以看到上面的脚本,说明我们网站还是加载Emoji表情的,这里是调用外部文件的,我们要么选择禁用,要么选择文档本地化,这样可以提高速度。
第二、禁用Emoji表情脚本
禁用表情可以直接使用Disable Emojis插件,但是我们还是本着能少用插件就少用的原则,直接使用在当前主题的Functions.php文件中添加下面脚本禁用。
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\\’ );
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( \\’wpemoji\\’ ) );
} else {
return array();
}
}
添加之后我们重新更新下博客的缓存就可以生效。
第三、Emoji表情本地化
或者,我们也可以采用imjeff的方法(www.imjeff.cn/blog/448/),将表情本地化,这样我们也可以使用表情(一般人是用不上的,如果你真用,那就本地化)
1、下载表情放到当前主题下
下载地址:https://soft.laozuo.org/wordpress/72×72.zip
我们将表情文件夹放到当前主题目录下,文件夹名称不要变。
2、将下面脚本放到当前主题下的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\\’).\\’/72×72/\\’;
}
//让文章内容和评论支持 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(\\’&#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;
}
这样Emoji本地化就解决了。
总结,蜗牛个人建议还是禁用掉算了,一般也没多大用途。
[便宜vps]历史优惠活动内容
猜你可能想看的VPS
- javascript 删除字符串的最后一个字符全球[VPS测评]
- 疯狂猜成语 图猜成语一个人拿本书看着对面的山水是什么成语?全球[VPS测评]
- 疯狂猜成语 图猜成语一个人在说话后面还站着两个人是什么成语?全球[VPS测评]
- RUU.CLOUD→免费送 200GB 空间网盘;500GB 空间 一次虚拟空间(主机)
- 任务管理器中的进程上下跳动 进程列表总是变无法选中怎么办?全球[VPS测评]
- 新商家慎重-YonZy→66 元 年 512MB 内存 6GB SSD 虚拟空间(主机)
- 看奈飞 VPS ¥29 月 512M 15G 硬盘 1T 流量 100M全球[VPS测评]
- imidc→6 折优惠“南非 CN2 线路”VPS $9 月 KVM 5全球[VPS测评]
- LunaNode→加拿大 法国按小时计费 KVM 月费 3.5 美元起全球[VPS测评]
- HostYun 全场9折优惠 月付15.3元 大带宽 512M 10G 全球[VPS测评]
- 如何通过正确整理旧文章来增加网站SEO优化全球[VPS测评]
- 建站云服务器选择高效云盘还是SSD硬盘?全球[VPS测评]
- Ucloud云服务器官方补贴 个人新用户北上广低至¥77/年;香港低至¥香港VPS[主机]
- Hkisl-288HKD 年 香港 LXC VPS 不限流量香港VPS[主机]
- LightCloud 2019 新春: 终身折扣 VDS折扣 充全球[VPS测评]
- CloudCone 512M 内存 10G SSD 512G流量 洛杉矶全球[VPS测评]
- CIO和其他IT领导者充分利用边缘计算增强业务的4个关键全球[VPS测评]
- SugarHosts,美国云服务器,洛杉矶cn2中美极速专线,香港建站服美国VPS[主机]
- HostKvm,香港云地VPS,全场八折,三网直连,电信CN2,2核4G香港VPS[主机]
- 紫云服务器怎么样?紫云香港云服务器1核1G2M仅65元/月香港VPS[主机]
- 邢志宏:加快推动高质量建设跨境电商综试区起势成势全球[VPS测评]
- 香港vps免费:青云互联,1核1G/50G硬盘/500GB流量/2M带宽香港VPS[主机]
- 言車新车|大阳VPS125混动踏板,长续航,代步通勤9980元起全球[VPS测评]
- 搬瓦工:全场VPS 9折优惠,10Gbps(美国cn2 gia+日本软银日本VPS[主机]
- 腾讯云香港轻量云2核2G服务器:30M带宽低至704元/年;2312元/香港VPS[主机]
- 众创逸云:元旦优惠活动,香港美国CN2云服务器4核4G30M,仅售309美国VPS[主机]
- 亿速云双12年终回馈:云服务器2折活动,订单满100元减50元全球[VPS测评]
- 亿速互联怎么样?香港沙田vps,2核1G3M云主机仅98元/月,780元香港VPS[主机]
- 六一云:香港CN2/洛杉矶高防/CDN,“返利+折扣”双优惠,折上折送实香港VPS[主机]
- 香港云服务器性价比高:香港云服务器哪家便宜香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-143957.html











