Disable WordPress Emojis

Disable WordPress Emojis

Frustrating as it may seem to most businesses, WordPress 4.2 came with an Emoji feature that allowed you to use the new Emojis in WordPress. Here’s how to disable the silly code it adds to your website’s <head> without using a plugin.

So you’ve upgraded to the latest version of WordPress only to find some rather odd code in your website’s <head>. Weird…

<script type="text/javascript">
window._wpemojiSettings = {"baseUrl":"http:\/\/s.w.org\/images\/core\/emoji\/72x72\/","ext":".png","source":{"concatemoji":"http:\/\/whatever.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.2"}};
!function(a,b,c){function d(a){var c=b.createElement("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f;c.supports={simple:d("simple"),flag:d("flag")},c.supports.simple&&c.supports.flag||(f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
</script>

And then,

<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>

It’s all put there by WordPress 4.2 to use the new Emojis. Don’t you dare try and edit the WordPress core! Read on.

Remove WordPress Emoji Without a Plugin

There IS a free plugin out there called, Disable Emojis, that does this for you automatically. But, if you’re like us, you like to keep your plugins to a minimum. Here’s the code to add to your theme’s functions.php file to disable all that silly code in your <head>.

if (!function_exists(disable_emojis)) {
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( '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', 'disable_emojis' );
}

You might be asking why we’re adding the whole if(!function_exists()) thing. That just protects you against scarey PHP errors if someone DOES actually install the Disable Emojis plugin. The code above is pretty much a perfect copy of the business-end of that plugin. So, we might as well wrap it in a !function_exists.

A special thanks to Ryan Hellyer for his Disable Emojis plugin. Again, the code above was taken from his work.

Credit where credit is due…

Leave a Reply