How to disable smileys/emojis in WordPress headers to speed up the site

Posted on in Categories Programming last updated March 1, 2017

WordPress has smileys or so-called emojis added in version 4.2+. It added emoji character using javascript and other junk. It slows down the site for no real reason, and I do not use it at all. Here is how to remove unnecessary HTML and emoji URL calls to every page of your site and speed up your site.

Disable WordPress emoji
Disable WordPress emoji

How to disable emojicons/smileys introduced with WordPress

Edit your functions.php (make a backup first) located in themes folder and append the following code. In my case it was located in /var/www/html/wp-content/themes/twentysixteen/functions.php file:
$ vi /var/www/html/wp-content/themes/twentysixteen/functions.php
Append the following to disable it:

// Code credit http://wordpress.stackexchange.com/questions/185577/disable-emojicons-introduced-with-wp-4-2
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' );
 
function disable_emojicons_tinymce( $plugins ) {
  if ( is_array( $plugins ) ) {
    return array_diff( $plugins, array( 'wpemoji' ) );
  } else {
    return array();
  }
}
// remove the DNS prefetch
add_filter( 'emoji_svg_url', '__return_false' );

(Code credit: Christine Cooper)

Save and close the file. This made my site load faster. I hope this helps someone else too.

4 comment

  1. Make Childtheme to edit functions.php, because an update will delete your changes.
    A better way is to write a plugin for changes like that.
    Use “My Custom Functions” Plugin for changes instead to write one by yourself.

    Greetings

  2. I think is better to do the change as plugin instead of modify functions.php of your theme because if you update your theme we can say good by to the change!.

Leave a Comment