失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > WordPress禁用Emoji表情和本地化Emoji提高网站速度

WordPress禁用Emoji表情和本地化Emoji提高网站速度

时间:2019-08-08 23:44:25

相关推荐

WordPress禁用Emoji表情和本地化Emoji提高网站速度

普通个人博客和网站应用WordPress事实上,该程序已经足够使用了,但由于官方维护和不断改进,在添加和纠正安全的同时,也会添加一些其他升级元素。这使我们正在使用它WordPress即使程序非常完美,目前也没有其他优秀的程序。CMS可以替代,只是臃肿,甚至加载一些外部调用。

特别是我国用户访问速度慢,比如在WordPress4.2版本后,增加了Emoji大多数用户无法使用外部调用表情。如果我们认为没有必要,我们可以根据以下方法之一删除或更换本地加载。

第一,检查是否有Emoji表情

如果查看源文件,可以看到上面的脚本,说明我们的网站还在加载Emoji表情,这里是调用外部文件,我们要么选择禁用,要么选择文档本地化,这样可以提高速度。

第二、禁用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表情本地化

或者,我们也可以使用它imjeff的方法(/blog/448/),将表情本地化,这样我们也可以使用表情(普通人不能使用,如果你真的使用,那么本地化)

1.下载表下载到当前主题下

下载地址:/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 .= ‘‘;

}

return $output;

}

这样Emoji本地化就解决了。

综上所述,老左个人建议禁用,一般用途不大。

如果觉得《WordPress禁用Emoji表情和本地化Emoji提高网站速度》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。