How to disable the Emoji support in WordPress

Since version 4.2, WordPress introduced the emoj support for its content editor. This functionality implies a specific HTTP call to the wp-emoji-release.min.js. library and even if it’s quite small in size, only 10.5 KB, preventing WordPress from loading it is considered a necessary action to increase your site speed and performance. If you’re not using emoji at all, please follow these instructions.

Let’s see how to remove the HTTP call to the emoji library. We have two possible methods:

  1. Disabling WordPress emoji library using a plugin
  2. Disabling WordPress emoji library via code

1. Disabling WordPress emoji library using a plugin

Disabilitare le Emojis di WordPress

if you don’t wanna modify any of your theme’s files, just download and install Ryan Hellyer’s Disable Emojis plugin. Activate it and et voilĂ : everything’s done. Now just check out the<head> section of your website: the wp-emoji-release.min.js library has just been removed.

Emoji Settings

If you’re running a WP multisite, you can use the Emoji Settings plugin which lets you disable the emoji library selectively per website.

2. Disabling WordPress emoji library via code

If you don’t want to install yet another plugin, there exists a very clean and effective solution. Just open your  theme’s functions.php file and add the following code:

/**
 * Disabling the emoji library in WordPress.
 */
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( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
}
add_action( 'init', 'disable_emojis' );

/**
 * This function removes the emoji support within the TinyMCE editor.
 * 
 * @param array $plugins 
 * @return array Difference between the two arrays.
 */
function disable_emojis_tinymce($plugins)
{
    if ( is_array( $plugins ) ) {
        return array_diff( $plugins, array( 'wpemoji' ) );
    }
    else return array();
}

/**
 * Remoing CDN hostnames from WordPress DNS prefetch.
 *
 * @param array $urls Sources URLs.
 * @param string $relation_type URL relation type.
 * @return array Difference between the two arrays.
 */
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
    if ( 'dns-prefetch' == $relation_type ) {
        /** This filter is documented in wp-includes/formatting.php */
        $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
        $urls = array_diff( $urls, array( $emoji_svg_url ) );
    }
return $urls;
}

This code is also available as snippet on Github.