145

So WP 4.2 introduced emojis (smileys) that basically adds JS and other junk all over your pages. Something some people may find shocking. How does one completely erase all instances of this?

2
  • 40
    I was so shocked I almost collapsed in my chair when I read the announcement
    – Tom J Nowell
    Apr 27, 2015 at 20:33
  • 2
    o_O ... 9_9 ... >:-(
    – cjbj
    Oct 10, 2016 at 8:20

7 Answers 7

203

We will hook into init and remove actions as followed:

function disable_wp_emojicons() {

  // all actions related to emojis
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
  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_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );

  // filter to remove TinyMCE emojis
  add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );

We will need the following filter function to disable TinyMCE emojicons:

function disable_emojicons_tinymce( $plugins ) {
  if ( is_array( $plugins ) ) {
    return array_diff( $plugins, array( 'wpemoji' ) );
  } else {
    return array();
  }
}

Now we breathe and pretend this feature was never added to core... particularly while tons of resolved bugs are yet to be implemented.

This is available as a plugin, Disable Emojis.

Alternatively, you can replace the smilies with the original versions from previous versions of WordPress using Classic Smilies.

Update

We can also remove the DNS prefetch by returning false on filter emoji_svg_url (thanks @yobddigi):

add_filter( 'emoji_svg_url', '__return_false' );
9
  • 27
    Thanks! I'm not sure why they didn't just allow people to enable / disable this via Settings -> Writing but it's definitely annoying. +1
    – Howdy_McGee
    Apr 27, 2015 at 19:42
  • 6
    Look forward to your "Disable emojicons" plugin in the repo or github ;-)
    – birgire
    Apr 27, 2015 at 19:44
  • 3
    there's a couple of them already ( which this is a copy ) wordpress.org/plugins/classic-smilies wordpress.org/plugins/disable-emojis
    – pcarvalho
    Apr 28, 2015 at 17:38
  • 3
    Thanks for the answer! I can't believe this is part of core, at least not with an "opt-in" or a way to disable it ~_~
    – phatskat
    Apr 29, 2015 at 21:47
  • 5
    And its shocking to see that they add 114 lines worth scripts and styles in the header that are not even minified. Thanks for the plugin... Jul 22, 2015 at 12:39
29

Better solution if you want to disable this: use a plugin.

Same code as from Christine's comments: https://wordpress.org/plugins/disable-emojis/

Same code that also fixes the smilies to be the older ones: https://wordpress.org/plugins/classic-smilies/

Source: Me, since I wrote that code in the first place. https://plugins.trac.wordpress.org/changeset/1142480/classic-smilies

2
15

This is the simple way to remove emoji. Add bellow code to your function.php

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' ); 
3
  • 3
    This was already covered in my question above.
    – Christine Cooper
    Jul 22, 2015 at 12:38
  • Thanks this removes the code nicely - oddly my pages take 2 to 3 seconds longer to load with this in my functions.php than without it.
    – Steve
    Jul 21, 2017 at 12:11
  • This should run via init. See my answer.
    – Christine Cooper
    Aug 19, 2017 at 17:35
2

If you want to prevent Wordpress from automatically converting your old school ASCII smilies to Unicode emojis (like ;-) to 😉) in your posts altogether, you might want to remove_filter('the_content', 'convert_smilies')

(Not 100% sure this is what the question's about, but this solved my problem and I hope it might be handy for someone.)

0

I've tried some codes above but the only codes works on my end is this one.

Don't forget to back-up your functions.php before implementing these codes.

// REMOVE WP EMOJI
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');

remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
3
  • Did you properly test the code in my answer?
    – Christine Cooper
    Jul 10, 2017 at 7:44
  • yes I've tried it many times, site is on cloudflare-nginx server Jul 10, 2017 at 8:23
  • Just double checked my code and it is working. When you add the code into your functions.php file, try setting a higher priority, like this: add_action( 'init', 'disable_wp_emojicons', 3 );
    – Christine Cooper
    Jul 10, 2017 at 9:22
-1

Good news, I added a feature request:

Introduce a new option to WordPress WP_EMOICONS in here https://core.trac.wordpress.org/ticket/38252

and apparently this has been marked as duplicate https://core.trac.wordpress.org/ticket/32102 so we may expect something like

define( 'WP_EMOICONS', false );

in the future WordPress releases.

2
  • 2
    It looks like ticket #32102 is closed with wontfix. +1 for trying and beeing optimistic ;-)
    – birgire
    Oct 7, 2016 at 14:13
  • 3
    ps: as far as I understand it, your ticket #38252 was closed because it was a duplicate to ticket #32102, that was previously closed as a wontfix. So it looks like plugins will have to sort this out, for days to come ;-) Hence voting it up for you being so optimistic ;-)
    – birgire
    Oct 7, 2016 at 14:23
-2

Since WordPress emoji are served from s.w.org and they are not compressed, this impacts the SVG loading time depending on how many emoji you are using, and can even throw warnings on Google’s PageSpeed Insights tool.

To fix this issue, you can serve the emoji directly from your WordPress site itself and not by making external calls through js.

This can be achieved by installing the plugin Compressed Emoji which is available for free in the WordPress.org plugin repository.

When the plugin is activated, the compression offers savings in the range of 3kb ~ 1.3kb (roughly %60) per emoji.

Source: WPTavern

Not the answer you're looking for? Browse other questions tagged or ask your own question.