how to disable wp emoji script

Understanding WP Emoji Script

WordPress automatically includes an emoji script on your website to handle emojis consistently across various devices and email clients. The script, known as wp-emoji-release.min.js, can add extra HTTP requests and slow down your website, especially if you’re aiming for speed optimization and your site doesn’t heavily rely on emojis.

Reasons to Disable WP Emoji Script

  • Performance Improvement: Reducing unnecessary HTTP requests can enhance the loading times and overall speed of your site.
  • Simplified Code: Helps in keeping your site’s code cleaner by removing non-essential script.
  • SEO Benefits: Faster load times can contribute to improved SEO rankings.

How to Disable WP Emoji Script

To disable the WP Emoji script, you have multiple methods, including using plugins or adding code snippets to your theme’s functions.php file. Below is a step-by-step guide for each method.

1. Plugin Method

Using a plugin is perhaps the simplest way to disable the emoji script for those who prefer not to touch the code.

Use of Plugin: Disable Emojis

  1. Go to your WordPress Dashboard.
  2. Navigate to ‘Plugins’ > ‘Add New’.
  3. Search for “Disable Emojis” plugin.
  4. Install and activate the plugin.
  5. The plugin works out-of-the-box and does not require any configuration.

This plugin specifically disables the emoji script, and the best part is that it is lightweight and straightforward.

2. Manual Code Method

For those who are comfortable with adding code to their WordPress files, this method allows more control and avoids the need for an additional plugin.

Edit the functions.php File:

  1. Navigate to ‘Appearance’ > ‘Theme Editor’ in WordPress dashboard.
  2. Select your active theme from the right-hand side.
  3. Find and click on the functions.php file.
  4. Carefully insert the following code at the end of the file:
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_filter('emoji_svg_url', '__return_false');
}

add_action('init', 'disable_emojis');

function disable_emojis_tinymce($plugins) {
    if (is_array($plugins)) {
        return array_diff($plugins, array('wpemoji'));
    } else {
        return array();
    }
}
  1. Save the changes.

This snippet of code removes emoji-related actions and filters, effectively disabling the WP emoji script across your WordPress site. It also modifies the TinyMCE editor used by WordPress to ensure emojis are not automatically handled there.

3. Using wp_dequeue_script()

For a more targeted approach, you may want to dequeue the emoji script directly if active on specific pages or site-wide.

Modify the functions.php File:

  1. Append the code below to your theme’s functions.php file:
function disable_wp_emojicons() {
  wp_dequeue_script('emoji');
}
add_action('wp_print_styles', 'disable_wp_emojicons');
  1. Save your changes.

This approach is straightforward and suits those who need minimal interference with their WordPress configurations.

Testing and Validation

After implementing any of the above methods, use browser tools like Chrome’s DevTools to inspect your website’s source code or network activity. Ensure no emoji-related scripts are loaded, and further, test your site’s performance through tools like Google’s PageSpeed Insights to observe any improvements in loading speed.

Maintaining Changes in Updates

Remember, if you modify the theme directly, your changes might be overwritten during theme updates. Therefore, use a child theme or ensure to reapply changes post updates. Similarly, for plugins, keep them updated to ensure compatibility and security.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *