Cleanup the head section HTML of a WordPress site

WordPress puts a lot of code in your head, some is useful, some might not be.
Use this snippet to get rid of the most common unwanted WordPress bloat.

// WordPress header cleanup
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Remove the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Remove the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Remove the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Remove the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // Remove the index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // Remove prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // Remove start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Remove relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Remove the WP version

While we’re at it… WordPress added emoji emoticons to the core since version 4.2. Fine if you’re hosting a blog and really need that animated dancing banana having fun skinning himself alive.
If you (like me) don’t fancy dancing banana’s; here’s how to get rid of the emoji-emoticon bloat in WordPress:

// Disable and remove Emoji Emoticons (since WP4.2)
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 (be sure to include the disable_emojicons_tinymce function! )
	add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );

function disable_emojicons_tinymce( $plugins ) {
	if ( is_array( $plugins ) ) {
		return array_diff( $plugins, array( 'wpemoji' ) );
	} else {
		return array();
	}
}

Leave a Reply