Remove Emoji code from WordPress and make your website faster

The following piece of code in your WordPress website’s code appears phishy? Well, it’s not. WordPress loads a bit of code to properly process and display those funny emojis ( similar to smileys or emoticons). However, this does involve additional HTTP requests and adds some extra load in terms of speed and rendering of your website.

Here’s the pieces of Emoji code WordPress adds in your website’s head:

<script type="text/javascript">
	window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/svg\/","svgExt":".svg","source":{"concatemoji":"http:\/\/www.bloghow.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.4.2"}};
	/*! This file is auto-generated */
	!function(e,a,t){var r,n,o,i,p=a.createElement("canvas"),s=p.getContext&&p.getContext("2d");function c(e,t){var a=String.fromCharCode;s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,e),0,0);var r=p.toDataURL();return s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,t),0,0),r===p.toDataURL()}function l(e){if(!s||!s.fillText)return!1;switch(s.textBaseline="top",s.font="600 32px Arial",e){case"flag":return!c([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])&&(!c([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!c([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]));case"emoji":return!c([55357,56424,55356,57342,8205,55358,56605,8205,55357,56424,55356,57340],[55357,56424,55356,57342,8203,55358,56605,8203,55357,56424,55356,57340])}return!1}function d(e){var t=a.createElement("script");t.src=e,t.defer=t.type="text/javascript",a.getElementsByTagName("head")[0].appendChild(t)}for(i=Array("flag","emoji"),t.supports={everything:!0,everythingExceptFlag:!0},o=0;o<i.length;o++)t.supports[i[o]]=l(i[o]),t.supports.everything=t.supports.everything&&t.supports[i[o]],"flag"!==i[o]&&(t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&t.supports[i[o]]);t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&!t.supports.flag,t.DOMReady=!1,t.readyCallback=function(){t.DOMReady=!0},t.supports.everything||(n=function(){t.readyCallback()},a.addEventListener?(a.addEventListener("DOMContentLoaded",n,!1),e.addEventListener("load",n,!1)):(e.attachEvent("onload",n),a.attachEvent("onreadystatechange",function(){"complete"===a.readyState&&t.readyCallback()})),(r=t.source||{}).concatemoji?d(r.concatemoji):r.wpemoji&&r.twemoji&&(d(r.twemoji),d(r.wpemoji)))}(window,document,window._wpemojiSettings);
</script>
<style type="text/css">
img.wp-smiley,
img.emoji {
	display: inline !important;
	border: none !important;
	box-shadow: none !important;
	height: 1em !important;
	width: 1em !important;
	margin: 0 .07em !important;
	vertical-align: -0.1em !important;
	background: none !important;
	padding: 0 !important;
}
</style>

If your site is not something where a lot of emojis will be needed, it should be fine to get rid of the extra “junk” and make your site faster and more SEO-friendly. In addition, this block of code had been the spot for malware infections in the past.

Quick, one-step process to remove the emoji code from WordPress

You will need to edit the functions.php file in your specific theme folder. Go to your WordPress installation location, find wp-content > themes, and then go inside the directory of the theme in use. You should find the functions.php file in there.

Here’s the code snippet you need to place in your theme’s functions.php file. Paste the code in a new line after the beginning <?php

remove_action('wp_head', 'print_emoji_detection_script', 7); // Remove Emoji code -BlogHow.com
remove_action('wp_print_styles', 'print_emoji_styles'); // Remove Emoji CSS and related stuff
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

That’s it. The emoji code should be gone! Make sure you clear the cache if you’re using a caching plugin.

There are a bunch of other code snippets you might want to clean up in default WordPress header. Follow the instructions on how to remove more junk from WordPress header, and you should now have a cleaner leaner page code.

Leave a Reply to Anonymous Cancel reply

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