Completely Removes Emoji

Completely removes emoji functionality from WordPress.

PHP
/**
 * Snippet Name:     Completely removes emoji
 * Snippet Author:   coding-bunny.com
 * Description:      Completely removes emoji functionality from WordPress.
 */

add_action( 'init', 'cb_disable_emoji' );

function cb_disable_emoji() {
    // Remove emoji detection script from frontend and admin head
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    
    // Remove emoji styles from frontend and admin
    remove_action( 'wp_print_styles', 'print_emoji_styles' );
    remove_action( 'admin_print_styles', 'print_emoji_styles' );
    
    // Remove emoji from content feeds and emails
    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 emoji from TinyMCE editor
    add_filter( 'tiny_mce_plugins', 'cb_remove_emoji_tinymce' );
}

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

// Remove emoji-related DNS prefetch
add_filter( 'wp_resource_hints', 'cb_remove_emoji_dns_prefetch', 10, 2 );

function cb_remove_emoji_dns_prefetch( $urls, $relation_type ) {
    if ( 'dns-prefetch' === $relation_type ) {
        $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
        $urls = array_diff( $urls, array( $emoji_svg_url ) );
    }
    return $urls;
}

How To Implement This Solution?

Leave a Reply

Your email address will not be published. Required fields are marked *

My Agile Privacy
This site uses technical and profiling cookies. You can accept, decline or customize cookies by pressing the desired buttons. By closing this policy you will continue without accepting.

Need help?

Choose one of the following options:

Powered by CodingBunny