Code Snippet to Disable WordPress Emoji Script for Improved Performance

Marek J Jan 11, 2025 Performance Optimization
How can I stop my website from using those little smiley face icons to make it load faster?
What is the code snippet to disable the default WordPress emoji script to enhance site performance?
Andy answered Jan 11, 2025

Disable WordPress Emoji Script

Custom Code Solution

Add this code to your theme's functions.php file or in a site-specific plugin. This code removes the WordPress emoji script and related files to improve page load times:

function disable_wp_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');

    // Remove TinyMCE emojis
    add_filter('tiny_mce_plugins', 'disable_wp_emojis_tinymce');
    
    // Remove emoji DNS prefetch
    add_filter('emoji_svg_url', '__return_false');
}
add_action('init', 'disable_wp_emojis');

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

What This Code Does

  1. Removes emoji detection script from front-end and admin
  2. Removes emoji styles
  3. Removes emoji from RSS feeds
  4. Removes emoji from emails
  5. Disables emoji in TinyMCE editor
  6. Removes emoji DNS prefetch

Plugin Alternative

If you prefer using a plugin, here are reliable options:

  1. Disable Emojis - Simple plugin that only removes emojis
  2. Asset CleanUp - More features including emoji removal and other performance optimizations

Additional Notes

  • This code is safe to use and won't affect regular text emoticons like :) or ;)
  • Users can still copy/paste emoji from other sources
  • The code maintains compatibility with existing content

After implementing either solution, clear your site's cache and CDN cache (if applicable) to see the changes take effect.