WordPress includes a lot of stuff through the
wp_head() hook included in most themes. Most of this stuff I would consider unnecessary. A few lines of extra code in your header probably won’t slow your site down that much, but I like to keep things as clean and efficient as possible.
In this quick tip post, I’ll go over how to remove the following from being output through the wp_head hook.
- Really Simple Discovery (RSD) link
- Windows Live Writer link
- WordPress generator notice
- Post relational links
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://example.com/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.
Windows Live Writer
This is why you see the following code in your header.
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://example.com/wp-includes/wlwmanifest.xml" />
If you don’t use Windows Live Writer, then this code is completely useless to you and should be removed.
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.
Post Relational Links
Post relational links are why this stuff is displayed on various pages.
<link rel='index' title='Main Page' href='http://www.themelab.com' /> <link rel='start' title='Article in the distant past' href='http://www.themelab.com/hello-world/' /> <link rel='prev' title='The Post Before This One' href='http://www.themelab.com/post-before/' /> <link rel='next' title='The Post After This One' href='http://www.themelab.com/post-after/' />
I have yet to find an actual reason to keep these around. 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');
For your convenience, here’s all of them combined for easy copying and pasting into your own theme’s
<?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'); ?>
In fact, this is the entire
functions.php file I’m using on my new tweet archive theme. If you take a look at the code, the
<head> tag only contains three lines: the meta charset declaration, the title tag, and the stylesheet link.
A Note About Released Themes
When you’re developing themes for release, be careful in removing some of these, especially the first two: XML-RPC and Windows Live Writer support.
The reason should be pretty obvious, because some of your users will likely use something like Windows Live Writer, and will come back to you asking for support when they can’t figure out why it doesn’t work with your theme.
The other items, the WordPress generator notice and post relation links, can probably be safely removed in almost any situation.
Like I said in the intro, it’s not a huge deal if you don’t remove these and I wouldn’t call this a “must” on every new WordPress site you develop. If you’re like me and don’t like useless lines of code, you’ll probably want to anyway just to keep things running as cleanly as possible.
Can you think of any other functions that you use to remove lines of unnecessary WordPress code? Let me know in the comments.
Looking for web hosting?
Question: What's the best type of web hosting?
Answer: The kind you don't have to worry about.
And that's precisely why I recommend HostGator. I've been using them myself for years and they've been nothing short of superb.
Fast load times, great support, WordPress-friendly, and good prices. Not much more you can ask for.
New customers can get 25% off of any HostGator web hosting package with the coupon: themelab25percentoffNote: I am a HostGator affiliate, but that doesn't make my recommendation any less genuine.