WordPress disables Emoji expressions and localizes Emoji to improve website speed

888u

Last update at :2024-07-04,Edit by888u

For ordinary personal blogs and website applications, the WordPress program is actually sufficient. However, due to official maintenance and continuous improvement, while adding and correcting security, some other upgrade elements will also be added. This makes us find that when using WordPress, even if the program is very perfect, there is currently no other excellent CMS that can replace it, but it is relatively bloated and even loads some external calls.

Especially for our users in mainland China, access is relatively slow. For example, after WordPress version 4.2, external calls to Emoji expressions were added, which are not available to most users. If we think it is not necessary, we can follow the method below. One of them removes or replaces the local load.

First, check whether there are Emoji expressions

If we view the source file, we can see the above script, which means that our website still loads Emoji expressions. Here, external files are called. We can either choose to disable it or choose document localization, which can improve the speed.

Second, disable Emoji expression scripts

To disable emoticons, you can directly use the Disable Emojis plug-in, but we still adhere to the principle of using plug-ins as little as possible and directly add the following script to disable them in the Functions.php file of the current theme.

/*** 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 ();}}

After adding it, we can update the cache of the blog to take effect.

Third, Emoji localization

Alternatively, we can also use imjeff's method (www.imjeff.cn/blog/448/) to localize emoticons, so that we can also use emoticons (most people cannot use them, but if you really use them, then Just localize)

1. Download the emoticon and put it under the current theme

Download address: https://soft.laozuo.org/wordpress/72×72.zip

We will put the emoticon folder in the current theme directory, and do not change the folder name.

2. Place the following script into the Functions.php file under the current theme

//First complete wp's emoticon library function smilies_reset() {global $wpsmiliestrans, $wp_smiliessearch;// don\\'t bother setting up smilies if they are disabledif (!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);}//Replace cdn path function static_emoji_url( ) {return get_bloginfo(\\'template_directory\\').\\'/72×72/\\';}//Let the article content and comments support emoji and disable the messy script function loaded by emoji 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); //Convert to emoticons and then to static images smileies_reset();add_filter(\\'emoji_url\\', \\'static_emoji_url\\' );}add_action(\\'init\\', \\'reset_emojis\\');//Output emoticon 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;}

This way Emoji localization is solved.

In summary, my personal suggestion is to disable Snail, as it is generally of little use.

Recommended site searches: free server Hong Kong server, domain name space proxy, virtual host control panel, virtual space host, Hengchuang host, IP proxy server, US host ranking, check IP detailed address, host server rental,

WordPress disables Emoji expressions and localizes Emoji to improve website speed

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码