← Back to All Snippets

Disable Emoji Scripts and Styles Completely in WordPress

⚡ Target: functions.php 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 Lang: PHP
PHP (functions.php)
add_action( 'init', function() {
    // Remove emoji actions from header and feeds
    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 emoji plugin and DNS prefetch
    add_filter( 'tiny_mce_plugins', function( $plugins ) {
        return is_array( $plugins ) ? array_diff( $plugins, [ 'wpemoji' ] ) : [];
    } );
    add_filter( 'wp_resource_hints', function( $urls, $relation_type ) {
        if ( 'dns-prefetch' === $relation_type ) {
            $urls = array_filter( $urls, function( $url ) {
                return false === strpos( $url, 'https://s.w.org/images/core/emoji/' );
            } );
        }
        return $urls;
    }, 10, 2 );
} );

WordPress loads unnecessary JavaScript and CSS styles on every page load to support legacy browser emojis. This snippet completely removes wp-emoji scripts, styles, and DNS prefetch requests to reduce HTTP requests.

← Back to All Snippets Explore Dev Tools →