How to Write a Plugin and Remove WordPress Emoji Code

The page speed for this website increased from an 88 to a 90 for desktop and from 67 to 70 for mobile devices by simply removing the new WordPress emoji abilities. I found the solution for how to remove the code on WordPress.org, but the question was immediately followed by another question asking how to implement it. I figured I would take you through the process of creating a custom plugin while I showed you one way to remove the Emoji code.

What are Emojis?

An emoji is defined as:

A small digital image or icon used to express an idea, emotion, etc., in electronic communication.

https://www.google.com/search?q=What+are+Emojis&oq=What+are+Emojis

Emoji Code Added In Recent WordPress Update

Screen Shot of Emoji Code

Screen Shot of Emoji Code Added to WordPress Site Source Code, Javascript and CSS

You may or may not have noticed but recent updates to WordPress added code into the backbone that also adds to your WordPress site source code. I was surprised when I saw the code the first time and I was worried that my site/ s may have been hacked. Turns out it wasn’t a hack. It was worse. WordPress generated the code and it was slowing down my sites.

The code consists of two parts, a javascript and CSS.

How to Create the Plugin to Remove Emoji Abilities

To create the plugin we must first open a text editor such as notepad. I actually used TextEdit on my mac. If you want to just skip down this page to the full code, please do.

The plugin requires a few parts that you can read about here.

Create the Plugin

You are going to be saving the text file with a .php extension and the plugin should start out with the opening php tag.

<?php

Next you will add a comment tag on it’s own line.

/*

You then need to state the Plugin Name and the description. After that you close the comment tag for the name and description. You will notice that I like to add a start functions line to keep things clear.

Plugin Name: Site Functions From jaxbeachwebsites.com
Description: Site specific code changes From jaxbeachwebsites.com
*/
/* Start Adding Functions Below this Line */

You can now add the functions to remove the emoji code. Much thanks to sabernhardt WordPress user for helping us figure this out.

/* START Function Remove Emoji Stuff */

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’ );

/* END Function Remove Emoji Stuff */

Now you need to close the php code. I will also add a comment to show where the code ends. This may seem unneeded for this short plugin, but if you want to extend this plugin in the future the comments always help keep things clean.

/* Stop Adding Functions Below this Line */
?>

Save Your Plugin

Using File -> Save As, save your file as site-functions.php

Compress/ ZIP Your Plugin

On my mac I first find my php file using Finder. I then right click, or control click on the file and choose “Compress File to ZIP.”

Install the Plugin and Activate

Now that the plugin to remove the emoji scripts and css has been created, it is time to install and activate the plugin. Log in to your WordPress site, hover over the Plugins menu, click Add New. Install the plugin and activate.

If you are using a caching plugin such as ZenCache, you may need to clear your caches.  Visit your site, view the source code, and you should see the code is gone!

Complete Plugin Code

<?php
/*
Plugin Name: Site Functions from jaxbeachwebsites.com
Description: Site specific code changes from jaxbeachwebsites.com
*/
/* Start Adding Functions Below this Line */
/* START Function Remove Emoji Stuff */

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’ );

/* END Function Remove Emoji Stuff */

/* Stop Adding Functions Below this Line */
?>

Download the Remove Emoji Plugin Zip File

Click Here-> jbw_custom_plugin.php

Comments are closed.