Remove Unnecessary Code from wp_head

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.

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://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.

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.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');

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.

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.

Comments   Leave a Reply

  1. Hello, I need help on WordPress that after making the page in WP I saw in the code (source code) that with every class name page builder has added his name which is confusing for me, for example, am using ELEMENTOR and making a page I saw in source code class name “.elementor-column-wrap”… now the problem is I want to remove the elementor words before the class name. I want to keep the class name as simple as that. no page builder name should be there… please let me know.

    1. You can’t remove it or you will break the Elementor

  2. Hello,

    Please tell me where to put this code in functions.php?
    Some blogs told that it should be put at the end, other blogs that it can be put in the beginning?

    Thanks in advance

    1. The position doesn’t matter at all. You can add it at the beginning or bottom.

  3. How can i remove from wp_head()

  4. Hello,
    Thanks for this post but please also add code to remove emoji script.

      1. Thank you very much for help. Just want to tell you that my site got speed of 99 on mobile and 98 on desktop in google page speed test because of code mentioned above in post and emoji removal code.

        1. I am glad it helped!

  5. I don’t know why do theme developers put these in their themes as default in the first place.

    I used a very basic theme and modified it to suit my website but all these junk was still in my header (among with some other junk WordPress automatically loads).

    Thanks for this post, I found it very useful.

  6. Just found this post based on the adjacent_posts_rel_link_wp_head – This may work for you and your audience so I think it’s relevant… not trying to spam but…
    I threw a handful of functions and cleanup type of stuff that I hope works for everybody’s installs to help clean it up and get rid of some of the crap like the wp_head stuff you’ve posted here.

    the plugin, for lack of a better name, is Selfish Fresh Start… selfish because it’s the stuff I feel should be removed from every install lol.


  7. Yes, it used wp_head. Is that something I need to worry about?

  8. I don’t have any of these in my header except for the WordPress generator – in my theme this is in a comment with “leave this for stats please”

    What’s that about?

    1. Does your theme use the wp_head hook? It sounds like that “leave this for stats” bit is hardcoded into your theme’s header.php file.

  9. Great stuff, although I should add that there’s been a little change in WP 3.0 with adjacent_posts_rel_link. It is now adjacent_posts_rel_link_wp_head (not sure why it changed).

    I figured that out by going to /wp-includes/default-filters.php and reversing what was listed in the add_action section.

    Any idea why that would have changed?

    1. We changed its name because we modified (improved) how it works in a backwards incompatible way. Fine for core, as it is an enhancement, but if a plugin was using the original plugin the way core does, we don’t want to alter that functionality.

      The new function actually just calls the old function — http://core.trac.wordpress.org/ticket/10867

  10. Hi. Do you know how I can remove jquery being called automatically? Obviously it needs to be called in the admin site, but client side, I use mootools, so don’t want two js libraries being called.


  11. Excellent post Leland! The relational links always bothered me a bit but I never looked into how to remove them.

    I think it’s also worth mention that a lot of the code added by plugins can also be removed: http://wptheming.com/2009/12/optimize-plug-in-script-wordpress/

    1. Hey Devin, thanks for the comment. That’s a good point about plugin code. Especially when plugins like Contact Form 7 automatically load up CSS and JS on every page, when you usually only need it on one (or any page you actually have a contact form).

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!