So WP 4.2 introduced emojis (smileys) that basically adds JS and other junk all over your pages. Something some people may find shocking. How does one completely erase all instances of this?
We will hook into init
and remove actions as followed:
function disable_wp_emojicons() {
// all actions related to emojis
remove_action( 'admin_print_styles', 'print_emoji_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_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
// filter to remove TinyMCE emojis
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );
We will need the following filter function to disable TinyMCE emojicons:
function disable_emojicons_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
Now we breathe and pretend this feature was never added to core… particularly while tons of resolved bugs are yet to be implemented.
This is available as a plugin, Disable Emojis.
Alternatively, you can replace the smilies with the original versions from previous versions of WordPress using Classic Smilies.
Update
We can also remove the DNS prefetch by returning false on filter emoji_svg_url
(thanks @yobddigi):
add_filter( 'emoji_svg_url', '__return_false' );