How to Disable WordPress Emoji Script

Johan S. Dec 21, 2024 Performance
How can I stop my website from using those smiley face icons?
What code snippet should I add to my theme's functions.php file to dequeue the WordPress emoji script for performance optimization?
Andy answered Dec 21, 2024

Disable WordPress Emoji Script

Custom Code Solution

Add this code to your theme's functions.php file or a site-specific plugin. This will remove the emoji script and related resources from WordPress:

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 the tinymce emoji plugin
    add_filter('tiny_mce_plugins', function($plugins) {
        if(is_array($plugins)) {
            return array_diff($plugins, array('wpemoji'));
        }
        return array();
    });
    
    // Remove emoji DNS prefetch
    add_filter('emoji_svg_url', '__return_false');
}
add_action('init', 'disable_wp_emojis');

Plugin Solutions

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

  1. Disable Emojis - Lightweight plugin specifically for removing emoji support
  2. Asset CleanUp - More feature-rich plugin that can disable emojis along with other optimizations

Benefits

  • Reduces HTTP requests
  • Removes unnecessary JavaScript and CSS
  • Slightly improves page load time
  • Cleaner source code

Important Notes

  • This won't remove emoji characters from your content
  • Users can still copy/paste emoji characters into posts
  • Mobile devices will still show their native emoji keyboard
  • Test your site after implementation to ensure nothing breaks