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 resources to improve page load time:
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 emojis
add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
// Remove emoji CDN hostname from DNS prefetching hints
add_filter('wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2);
}
add_action('init', 'disable_wp_emojis');
// Filter function to remove the TinyMCE emoji plugin
function disable_emojis_tinymce($plugins) {
if (is_array($plugins)) {
return array_diff($plugins, array('wpemoji'));
}
return array();
}
// Remove emoji CDN hostname from DNS prefetching hints
function disable_emojis_remove_dns_prefetch($urls, $relation_type) {
if ('dns-prefetch' === $relation_type) {
$urls = array_diff($urls, array('https://s.w.org/images/core/emoji/'));
}
return $urls;
}
Plugin Solutions
If you prefer using a plugin, here are reliable options:
-
Disable Emojis - Simple plugin that removes emoji support
-
Asset CleanUp - More advanced plugin that can disable emojis along with other WordPress optimizations
Benefits
- Reduces HTTP requests
- Removes unnecessary JavaScript
- Improves page load time
- Cleaner source code
Important Notes
- This code is compatible with all WordPress versions
- Test your site after implementation to ensure no conflicts with other functionality
- If you're using a caching plugin, clear the cache after adding this code
- Some themes might have their own emoji implementations which this code won't affect