Snippet

Disable Emojis in WordPress

Since version 4.2, WordPress adds an emoji script and some CSS to every page, so emojis show up nicely even in old browsers. Modern browsers and phones already show emojis on their own, so for most websites this is extra code that loads for nothing. If you want to keep your pages a little lighter, you can switch it off using the following code. Your emojis will still appear, the browser just draws them by itself. For more ideas like this, see our tips on how to increase website speed.

Where to place? functions.php of your child theme, or a code snippets plugin.

Usage

  • To remove a script and a block of CSS from every page of your website.
  • On websites that rarely use emojis, such as business or documentation websites.
  • As part of a speed clean-up, along with removing other things your website doesn’t use.

Code


// Disable the emoji script and styles WordPress adds to every page
function wpt_disable_emojis() {
  remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  remove_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' );
  remove_action( 'admin_enqueue_scripts', 'wp_enqueue_emoji_styles' );
  remove_action( 'wp_print_styles', 'print_emoji_styles' );
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
  remove_action( 'embed_head', 'print_emoji_detection_script' );
  remove_action( 'enqueue_embed_scripts', 'wp_enqueue_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( 'emoji_svg_url', '__return_false' );
}
add_action( 'init', 'wpt_disable_emojis' );
add_action( 'admin_init', 'wpt_disable_emojis' );

Explanation

  1. Just a comment to identify the code.
  2. Declaring our function wpt_disable_emojis.
  3. Removing the emoji detection script from the head of your pages.
  4. Removing the same script from the dashboard.
  5. Removing the emoji CSS from the front end of your website.
  6. Removing the emoji CSS from the dashboard.
  7. Removing the older way WordPress prints the emoji CSS, which it still keeps for compatibility.
  8. Doing the same in the dashboard.
  9. Removing the emoji script from embeds, the preview boxes other websites show when they link to your posts.
  10. Removing the emoji CSS from those embeds.
  11. Stopping WordPress from turning emojis into images in your RSS feed.
  12. Doing the same for comments in the feed.
  13. Doing the same for emails WordPress sends.
  14. Removing the link WordPress adds to load emoji images from its servers.
  15. Closing the function.
  16. Running our function on the init hook, after WordPress has added its own emoji code, so there is something to remove.
  17. Running it once more on admin_init, because the dashboard adds its emoji code later than the front end.