Last updated on September 24, 2023

Remove the WordPress Emoji Scripts and Styles

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Remove emoji scripts for cleaner code.

The code snippet below will remove the WordPress emoji scripts and styles from your website. This can be useful if you want to improve the performance of your site by reducing unnecessary script and style files.

function wpsnippets_remove_emoji_scripts() {
    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' );
    add_filter( 'tiny_mce_plugins', 'wpsnippets_remove_emoji_tinymce' );
}
add_action( 'init', 'wpsnippets_remove_emoji_scripts' );

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

This code snippet uses the remove_action() and remove_filter() functions to remove the emoji scripts and styles from various hooks and filters. It also adds a filter to remove the emoji plugin from the TinyMCE editor. By adding this code to your theme’s functions.php file or a custom plugin, the emoji scripts and styles will no longer be loaded on your website.

Examples

Example 1: Removing Emoji Scripts and Styles using functions.php

This example demonstrates how to remove the Emoji scripts and styles from your WordPress website by adding a code snippet to the functions.php file of your theme.

function wpsnippets_remove_emoji_scripts_styles() {
    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' );
}
add_action( 'init', 'wpsnippets_remove_emoji_scripts_styles' );

This code snippet uses the remove_action() and remove_filter() functions to remove the Emoji scripts and styles from the WordPress website. It hooks into the init action to ensure that the Emoji scripts and styles are removed early in the WordPress initialization process.

Example 2: Removing Emoji Scripts and Styles using a Plugin

This example demonstrates how to remove the Emoji scripts and styles from your WordPress website using a custom plugin.

/**
 * Plugin Name: Remove Emoji Scripts and Styles
 * Description: Removes the Emoji scripts and styles from the WordPress website.
 */

function wpsnippets_remove_emoji_scripts_styles() {
    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' );
}
add_action( 'init', 'wpsnippets_remove_emoji_scripts_styles' );

This code creates a custom plugin that removes the Emoji scripts and styles from the WordPress website. The remove_action() and remove_filter() functions are used to remove the Emoji scripts and styles, and the code is hooked into the init action to ensure early removal.

Example 3: Removing Emoji Scripts and Styles using a Must-Use Plugin

This example demonstrates how to remove the Emoji scripts and styles from your WordPress website using a must-use plugin.

Create a file named remove-emoji-scripts-styles.php and place it in the wp-content/mu-plugins/ directory.

<?php
/**
 * Plugin Name: Remove Emoji Scripts and Styles
 * Description: Removes the Emoji scripts and styles from the WordPress website.
 */

function wpsnippets_remove_emoji_scripts_styles() {
    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' );
}
add_action( 'init', 'wpsnippets_remove_emoji_scripts_styles' );

This code creates a must-use plugin that removes the Emoji scripts and styles from the WordPress website. The remove_action() and remove_filter() functions are used to remove the Emoji scripts and styles, and the code is hooked into the init action to ensure early removal. The must-use plugin is automatically loaded by WordPress, so there is no need to activate it.

Last updated on September 24, 2023. Originally posted on September 26, 2023.

Leave a Reply