How to Disable Emojis in WordPress (Step by Step)

3 days ago, WordPress Plugin, 2 Views
How to disable emojis in WordPress 4.2

Introduction: Why Disable Emojis in WordPress?

While emojis are widely used and enjoyed on the internet, they might not be suitable for every website. WordPress, by default, automatically converts certain text strings into emojis. This functionality can be problematic for several reasons:

* Performance Issues: WordPress’s emoji implementation loads extra JavaScript and CSS files, which can increase your website’s page load time, especially for users who don’t even see or use emojis.
* Conflicting Plugins: Some plugins might also handle emojis, leading to conflicts and unexpected behavior on your website.
* Design Consistency: You might prefer to use a custom emoji set or simply stick to text-based emoticons for a more consistent design.
* Clean Codebase: Removing unnecessary code, like the emoji script, contributes to a leaner and faster website.

Disabling emojis can improve your website’s performance, resolve conflicts, and give you more control over its appearance. This article will guide you through various methods to disable emojis in WordPress, ranging from simple plugin installations to code-based solutions.

Method 1: Using a Plugin (Recommended for Beginners)

The easiest way to disable emojis in WordPress is by using a plugin. Several plugins are specifically designed for this purpose, offering a simple and user-friendly interface.

Step 1: Install and Activate the “Disable Emojis” Plugin

1. Log in to your WordPress admin dashboard.
2. Navigate to “Plugins” -> “Add New.”
3. In the search bar, type “Disable Emojis.”
4. Find the plugin called “Disable Emojis” (by Ryan Hellyer) and click “Install Now.”
5. Once installed, click “Activate.”

Step 2: Configure the Plugin (Optional)

The “Disable Emojis” plugin typically works out of the box. After activation, it automatically disables most emoji-related functionality. However, some plugins offer additional configuration options.

1. Go to “Settings” if a settings page is offered. In most cases the Disable Emojis plugin has no settings to configure. It just works when it’s active.
2. If there is a settings page, review the options. Some plugins might allow you to choose specific emoji features to disable or enable.
3. Save any changes you make to the settings.

Advantages of Using a Plugin:

* Easy to install and activate.
* No coding knowledge required.
* Typically lightweight and efficient.
* Some plugins offer additional configuration options.

Disadvantages of Using a Plugin:

* Adds another plugin to your WordPress installation.
* Reliance on a third-party plugin, which might become outdated.

Method 2: Adding Code to Your `functions.php` File

If you’re comfortable with code, you can disable emojis by adding a few lines to your theme’s `functions.php` file or by using a code snippets plugin.

Step 1: Access Your `functions.php` File

There are several ways to access your `functions.php` file:

* **WordPress Theme Editor:** Go to “Appearance” -> “Theme Editor” in your WordPress admin dashboard. Find the `functions.php` file in the list of theme files on the right-hand side. **Caution:** Directly editing theme files can be risky. Always back up your website before making changes.
* **FTP Client:** Use an FTP client (like FileZilla) to connect to your website’s server. Navigate to the `/wp-content/themes/your-theme-name/` directory and find the `functions.php` file.
* **File Manager:** Most web hosting providers offer a file manager within their control panel. Use the file manager to navigate to the same directory as mentioned above and find the `functions.php` file.

Step 2: Add the Code Snippet

Add the following code snippet to your `functions.php` file:

“`php
function disable_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( ‘wp_mail’, ‘wp_staticize_emoji_for_email’ );
remove_filter( ‘the_content_feed’, ‘wp_staticize_emoji’ );
remove_filter( ‘comment_text_rss’, ‘wp_staticize_emoji’ );

// Disable TinyMCE emojis.
add_filter( ‘tiny_mce_plugins’, ‘disable_emojis_tinymce’ );
}
add_action( ‘init’, ‘disable_emojis’ );

function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( ‘wpemoji’ ) );
} else {
return array();
}
}

add_filter( ‘wp_resource_hints’, ‘disable_emojis_remove_dns_prefetch’, 10, 2 );

function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
if ( ‘dns-prefetch’ == $relation_type ) {
/** This filter is documented in wp-includes/formatting.php */
$emoji_svg_url_bit = apply_filters( ’emoji_svg_url’, ‘https://s.w.org/images/core/emoji/14.0.0/svg/’ );

$urls = array_diff( $urls, array( $emoji_svg_url_bit ) );
}

return $urls;
}
“`

Step 3: Save the Changes

After adding the code, save the `functions.php` file. If you’re using the WordPress theme editor, click the “Update File” button. If you’re using an FTP client or file manager, upload the modified file to your server.

Step 4: Using a Code Snippets Plugin (Alternative to Editing `functions.php`)

Editing the `functions.php` file directly can be risky because a syntax error could break your website. Using a code snippets plugin is a safer alternative.

1. Install and activate a code snippets plugin like “Code Snippets.”
2. Go to “Snippets” -> “Add New.”
3. Give your snippet a title (e.g., “Disable Emojis”).
4. Paste the code snippet from Step 2 into the code area.
5. Choose “Run snippet everywhere” or the appropriate execution scope.
6. Save and activate the snippet.

Explanation of the Code Snippet:

* `remove_action( ‘wp_head’, ‘print_emoji_detection_script’, 7 );`: Removes the script that detects emoji support.
* `remove_action( ‘admin_print_scripts’, ‘print_emoji_detection_script’ );`: Removes the emoji detection script from the admin area.
* `remove_action( ‘wp_print_styles’, ‘print_emoji_styles’ );`: Removes the emoji-related CSS styles.
* `remove_action( ‘admin_print_styles’, ‘print_emoji_styles’ );`: Removes the emoji-related CSS styles from the admin area.
* `remove_filter( ‘wp_mail’, ‘wp_staticize_emoji_for_email’ );`: Prevents emojis from being converted in emails.
* `remove_filter( ‘the_content_feed’, ‘wp_staticize_emoji’ );`: Prevents emojis from being converted in RSS feeds.
* `remove_filter( ‘comment_text_rss’, ‘wp_staticize_emoji’ );`: Prevents emojis from being converted in comment RSS feeds.
* `disable_emojis_tinymce()`: Removes the emoji plugin from the TinyMCE editor.
* `disable_emojis_remove_dns_prefetch()`: Removes the emoji-related DNS prefetch.

Advantages of Using Code:

* No need to install an extra plugin.
* Direct control over the emoji disabling process.
* Can be easily customized and extended.

Disadvantages of Using Code:

* Requires some coding knowledge.
* Risk of breaking your website if the code is incorrect.
* Changes to the `functions.php` file might be overwritten during theme updates (use a child theme to avoid this).

Method 3: Using a Child Theme

If you choose to add the code to your theme’s `functions.php` file, it’s highly recommended to use a child theme. A child theme inherits the functionality and styling of its parent theme but allows you to make modifications without directly altering the parent theme files. This is important because when you update your parent theme, any changes you’ve made to its `functions.php` file will be lost.

Step 1: Create a Child Theme

1. **Create a new directory** in `/wp-content/themes/`. Name it something like `your-theme-name-child`, replacing `your-theme-name` with the actual name of your parent theme.
2. **Create a `style.css` file** inside the new directory. Add the following code to the `style.css` file, replacing `your-theme-name` with the actual name of your parent theme:

“`css
/*
Theme Name: Your Theme Name Child
Theme URI: http://example.com/your-theme-child/
Description: Your Theme Name Child Theme
Author: Your Name
Author URI: http://example.com
Template: your-theme-name
Version: 1.0.0
*/

/* =Theme customization starts here
————————————————————– */
“`
3. **Create a `functions.php` file** in the same directory as the `style.css` file. This file is where you’ll add the emoji disabling code.

Step 2: Activate the Child Theme

1. Go to “Appearance” -> “Themes” in your WordPress admin dashboard.
2. Find your child theme and click “Activate.”

Step 3: Add the Emoji Disabling Code to the Child Theme’s `functions.php` File

Follow the instructions in Method 2, Step 2 to add the code snippet to your child theme’s `functions.php` file.

Advantages of Using a Child Theme:

* Preserves your customizations during theme updates.
* Provides a safe way to modify your theme’s functionality and appearance.

Disadvantages of Using a Child Theme:

* Requires creating a child theme, which adds a few extra steps.

Method 4: Checking for Emoji Support and Conditionally Disabling

This method allows you to check if the user’s browser actually supports native emojis before disabling the WordPress emoji functionality. This can be beneficial if you want to provide the best possible experience for users with modern browsers while still improving performance for those with older browsers.

Step 1: Add the Conditional Code to Your `functions.php` File (or Code Snippet Plugin)

Add the following code snippet to your `functions.php` file (or use a code snippets plugin as described in Method 2):

“`php
function conditionally_disable_emojis() {
// Check if the browser supports native emojis
$supports_emojis = false;
if ( isset( $_SERVER[‘HTTP_USER_AGENT’] ) ) {
$user_agent = $_SERVER[‘HTTP_USER_AGENT’];
// Simplified User-Agent check (not exhaustive)
if ( stripos( $user_agent, ‘Android’ ) !== false || stripos( $user_agent, ‘iOS’ ) !== false || stripos( $user_agent, ‘Mac OS X’ ) !== false ) {
$supports_emojis = true; // Assume basic support in these OS
}
}

// Only disable emojis if native emojis are NOT supported
if ( ! $supports_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( ‘wp_mail’, ‘wp_staticize_emoji_for_email’ );
remove_filter( ‘the_content_feed’, ‘wp_staticize_emoji’ );
remove_filter( ‘comment_text_rss’, ‘wp_staticize_emoji’ );

add_filter( ‘tiny_mce_plugins’, ‘disable_emojis_tinymce’ );
add_filter( ‘wp_resource_hints’, ‘disable_emojis_remove_dns_prefetch’, 10, 2 );
}
}
add_action( ‘init’, ‘conditionally_disable_emojis’ );

function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( ‘wpemoji’ ) );
} else {
return array();
}
}

function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
if ( ‘dns-prefetch’ == $relation_type ) {
/** This filter is documented in wp-includes/formatting.php */
$emoji_svg_url_bit = apply_filters( ’emoji_svg_url’, ‘https://s.w.org/images/core/emoji/14.0.0/svg/’ );

$urls = array_diff( $urls, array( $emoji_svg_url_bit ) );
}

return $urls;
}
“`

Explanation of the Code:

1. **User-Agent Check:** The code checks the `HTTP_USER_AGENT` server variable to determine the user’s operating system. It makes a simplified assumption that Android, iOS, and Mac OS X likely support native emojis. **Important:** This is a simplified check and may not be completely accurate. A more robust check would involve detecting specific browser versions or features.
2. **Conditional Disabling:** If the browser is *not* detected as likely supporting native emojis, the code then proceeds to disable the WordPress emoji functionality using the same methods as in Method 2.

Advantages of Conditional Disabling:

* Potentially provides the best user experience by only disabling emojis for users who don’t have native support.
* Improves performance for users with older browsers or operating systems.

Disadvantages of Conditional Disabling:

* The User-Agent check is not 100% reliable.
* Requires a slightly more complex code snippet.

Verifying That Emojis are Disabled

After implementing any of the methods above, it’s important to verify that emojis are indeed disabled on your website.

* **Check the Source Code:** View the source code of a page on your website (usually by right-clicking and selecting “View Page Source”). Look for the following lines:
* `