25% off ProSNIPC25OFF

How to disable emojis in WordPress (and why it speeds up your pages)

The SnipCraft team

Modern browsers render emoji natively, but WordPress still ships a detection script, inline styles, and a DNS-prefetch hint on every page to support ancient browsers. Here’s how to remove all of it.

What WordPress loads for emoji

Out of the box, every front-end and admin page includes:

  • wp-emoji-release.min.js and an inline detection script in the <head>
  • Inline emoji CSS
  • A dns-prefetch hint to s.w.org

It’s small, but it’s an extra request and a few hundred bytes on every page, and it’s pure legacy support you almost certainly don’t need.

The snippet

This removes the scripts, styles, feed filters, the TinyMCE plugin, and the DNS-prefetch entry:

php
<?php
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', function ( $plugins ) {
    return is_array( $plugins ) ? array_diff( $plugins, array( 'wpemoji' ) ) : array();
} );

add_filter( 'wp_resource_hints', function ( $urls, $relation_type ) {
    if ( 'dns-prefetch' === $relation_type ) {
        $urls = array_filter( $urls, function ( $url ) {
            $href = is_array( $url ) ? ( isset( $url['href'] ) ? $url['href'] : '' ) : (string) $url;
            return strpos( $href, 's.w.org' ) === false;
        } );
    }
    return $urls;
}, 10, 2 );

Will I lose emoji?

No. This only removes WordPress’s polyfill. Emoji you type still display fine in any browser from the last decade, because they’re rendered by the operating system’s font, not by WordPress.

Note

This is a ready-made snippet in SnipCraft. Grab it here. Pair it with other performance snippets to trim requests without a heavyweight optimization plugin.
#performance#php