How to Turn Off WordPress Emojis and Disable Smiley Face Scripts Without Using a Plugin

by | December 28, 2020 | Website Development

This page may contain affiliate links to recommended products or services. If you choose to purchase after clicking a link, I may receive a commission at no additional cost to you.

Last updated on: August 9, 2022

Need to know how to turn off WordPress emojis and disable smiley face scripts without using a plugin? I feel you. Not every WordPress website needs emojis and smiley faces showing up in pages and blog posts. The good news is they’re easy to turn off and disable.

Could you use a plugin to disable WordPress emojis? Yes, of course.

Do you need to use a plugin to disable WordPress emojis? Nope.

You can manually (“programmatically”) disable WordPress emojis as long as you have access to your WordPress theme files and a text editor.

No Plugins Necessary

It’s a straight forward thing to do and I’m going to provide you with a snippet of code to use to do it (scroll down a little if you’re just here for the code).

In case you’re old school and don’t know what an emoji is, it’s the fancy way of saying smiley faces. They’re great for sending text messages from your smart phone, but if you’re running a business blog or corporate website then there’s a good chance you don’t need every semi-colon + close parentheses turning into a smiling yellow ball staring back at you from your walls of article-text.

WordPress loads with smileys of the box – smiley face text-to-smiley image conversion is turned on and enabled. Yuck!

Blacklisting WP Emojis

As a long time WordPress user, having to blacklist features you don’t want – as opposed to white listing features you do want – is something that grinds my gears. It makes sense that a robust feature-rich content management system like WordPress needs to come with some features enabled by default, but smiley faces? C’mon, man! Really? Not on my website, good sirs (madams?) — not on my website.

By default, WordPress loads emoji JavaScript files and CSS stylesheets whether you want them or not (and you don’t).

Now, it’s one thing to not use emojis on your website. That’s totally fine and dandy. But, not using emojis isn’t the same as disabling emojis and bouncing them out of the club.

Reduce Code Bloat

The big downer of these unwanted pests is that using them requires additional JavaScript files and CSS stylesheets to be loaded. When you’re not using the scripts or styles you’re just loading extra unnecessary stuff. Loading extra unnecessary stuff slows down websites and slow websites suck. They suck to load, they suck to browse, they suck ranking in search results. Pick your poison — there’s plenty of perfectly justifiable reasons to avoid loading excess goods on any web page.

Disable WordPress Emojis (Copy + Paste Code)

Without further ado, let’s turn your frown upside down and disable those smiley face emojis, their scripts, and styles – without using a plugin! Because adding another plugin seems a lot like loading more extra unnecessary stuff and I just told you how bad that is, so avoid doing that whenever possible.

Copy the code below and paste it into your WordPress theme’s functions.php file — every WordPress theme has a functions.php file, so yours will too. It’s where this code needs to go for it to disable WP emojis on your website.

You can paste it anywhere in the file – as in, at the top, the bottom, or somewhere in the middle – just don’t paste it inside of another block of code. If you’re a coding novice — or a normal person — then going to the bottom of the file, hitting enter a couple times to create some space and new lines, and pasting it at the very end is your safest choice. It’s going to take effect immediately, so if you go back to the public facing part of your website and hit refresh and it’s not instantly broken then you can rest assured that you did a good job.

add_action( 'init', 'disable_emojis' );

/**
* Disable the emjois
**/
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 );
}

/**
* Filter function used to remove the tinymce emoji plugin.
*
* @param array $plugins
* @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce( $plugins ) {

    if ( is_array( $plugins ) ) {

        return array_diff( $plugins, array( 'wpemoji' ) );

    } else {

        return array();

    }

}

/**
 * Remove emoji CDN hostname from DNS prefetching hints.
 *
 * @param array $urls URLs to print for resource hints.
 * @param string $relation_type The relation type the URLs are printed for.
 * @return array Difference betwen the two arrays.
 */
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {

    if ( 'dns-prefetch' == $relation_type ) {

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

Wabam! There you have it.

No more emojis for your WordPress website on the front-end, the back-end admin dashboard, in print, feeds, and the text editors.

Bye, bye WP emojis! 🙂

No More WP Emojis! Code Explained

Want to know what you did by copying and pasting this code inside of your WP theme’s functions.php file? Let’s run through removing emojis from WordPress in more detail.

add_action( 'init', 'disable_emojis' );

First, there’s a call to add_action(). add_action() is a handy built-in WordPress function that lets you run a “function” (i.e. an action) at different points through WordPress’s loading process. In WordPress language, those points are called hooks. actions latch on to hooks. Hooks are named designations that exist at various points through WordPress – the hook you’re using here is named init. If you can imagine, init is the hook you can use to run actions on as WordPress initializes (i.e. loads or boots up).

WP lets you create your own hooks and actions, but there’s plenty of default hooks, so we’re latching onto one of those because when it comes to disabling WP emojis it makes sense to do so.

In this case, you are adding an action to the init hook. The action is a function and we’ve arbitrarily named the function disable_emojis because that’s what you want to do. Plus, self-descriptively naming things like functions adds a layer of semantics and just makes code more understandable to read (for you or anyone else who might need to poke around in your codebase).

So far, so good? You’re adding an action to the init hook the executes a function that does a bunch of stuff – namely, shuts off WP emojis everywhere possible.

Next, there’s the action function – function disable_emojis() { }.

Inside the function, it looks like there’s a lot going on. That’s because WordPress is very thorough about adding emojis to everything, so you’re going to be thorough about removing emojis from everything. Inside of the WP ecosystem, emojis creep up nearly everywhere.

    // Remove WP emojis scripts from the public site's HEAD
    remove_action( 'wp_head', 'print_emoji_detection_script', 7);

    // Remove WP emojis from admin-side print sscripts
    remove_action( 'admin_print_scripts', 'print-emoji_detection_script' );

    // Remove WP emojis print stylesheet from the public side of the site
    remove_action( 'wp_print_styles', 'print_emoji_styles' );

    // Remove WP emojis print stylesheets from the admin-side of the site
    remove_action( 'admin_print_styles', 'print_emoji_styles' );

    // Remove WP emojis from content feeds
    remove_filter( 'the_content_feed', 'wp_staticize_emoji' );

    // Remove WP emojis from comment RSS text
    remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );

    // Remove WP emojis from WP created emails
    remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );

    // Disable WP emojis in the TinyMCE text editors (i.e. the old WP text editors that some folks still use)
    add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );

    // Tell the web browser to stop prefetching emoji scripts and styles because they're disabled
    add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );

To completely get rid of emojis in WordPress you need to disable them from print, email, RSS feeds, comments, content, and text editors. Once you’ve disabled smiley faces in all of those places you also want to stop the JavaScripts and CSS styles from loading. And finally, you tell WordPress to stop prefetching the the scripts and styles because there’s no more scripts and styles to prefetch.

Prefetching helps browsers load external resources faster – like scripts and stylesheets — so, it’s a very useful feature, but when you don’t need a feature you don’t need to load the feature. 

In a nut shell, this disable_emojis action takes care of cutting the head off our proverbial smiling snake.

Disable Emojis Using a WP Plugin

I don’t like to use plugins when they are not needed, but sometimes you have no choice.

If you don’t have access to your WordPress theme’s files then you are going to have to use a WP plugin to disable emojis. The GDPR friendly Disable Emojis plugin is good for that and can be installed from your WordPress dashboard the same as any other plugin.

Floyd Hartford is a website developer from southern Maine. He's focused on creating and building WordPress websites and loves spending time digging into code like HTML, CSS, scss, jQuery, PHP, and MySQL.

0 Comments

Submit a Comment

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

four + 8 =

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Looking for WordPress Help?

I’m a freelance web developer specializing in small business and corporate marketing websites.

Pin It on Pinterest