Cleaning WordPress Header by Removing Unnecessary Code

in your wordpress CMS you notice there are alot of stuffs through the wp_head() hook included on most well known themes and most of this stuffs is considered unnecessary, specially when using wordpress as a small business CMS rather than of a blog

Read on for the description of each of these to see if you need them or not, and how to remove them.

Really Simple Discovery
This is the code that displays the following code in your header:

<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://domain.tld/xmlrpc.php?rsd" />

This is the discover mechanism used by XML-RPC clients. If you have no idea what this means and/or don’t integrate services like Flickr with your WordPress site, it’s probably safe to remove it with the following code in your theme’s functions file.

remove_action('wp_head', 'rsd_link');

Windows Live Writer
This is why you see the following code in your header.

<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://domain.tld/wp-includes/wlwmanifest.xml" />

If you don’t use Windows Live Writer, then this code is completely useless to you and should be removed.

remove_action('wp_head', 'wlwmanifest_link');

WordPress Generator

This is what displays your WordPress version number in your header.

<meta name="generator" content="WordPress 2.8.4" />

Noone really needs to know the exact version of WordPress you’re using, so it’s safe to remove this line of code.

remove_action('wp_head', 'wp_generator');

Post Relational Links
Post relational links are why this stuff is displayed on various pages.

<link rel='index' title='Main Page' href='http://www.domain.tld' />
<link rel='start' title='Article in the distant past' href='http://www.domain.tld/hello-world/' />
<link rel='prev' title='The Post Before This One' href='http://www.domain.tld/post-before/' />
<link rel='next' title='The Post After This One' href='http://www.domain.tld/post-after/' />

Some browsers may use this code to navigate your site, although you can probably get the same effect from a well designed theme. You’ll need three lines to nuke them all

remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');

Functions.php Template

For your convenience, here’s all of them combined for easy copying and pasting into your own theme’s functions.php file.

<?php
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
?>

2 thoughts on “Cleaning WordPress Header by Removing Unnecessary Code

  1. Fanatic

    Anyone know to remove the meta name version code??
    I have this line of code on all the pages which is totally useless:

    Reply

Leave a Reply

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