Regain control of your WordPress head element

Reading time: About 1 minute

Inside your wordpress <head> element is a bunch of poorly marked-up link elements among other things. The bad code looks like this:

WordPress junk in my <head>

1
2
3
4
5
6
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://briancray.com/wp-includes/wlwmanifest.xml" />
<link rel='index' title='Brian Cray&#039;s Blog' href='http://briancray.com' />
<link rel='start' title='Open for business' href='http://briancray.com/2009/02/05/open-for-business/' />
<link rel='prev' title='5 great examples of popular blog posts that you should know' href='http://briancray.com/2009/08/12/5-great-examples-of-popular-blog-posts-that-you-should-know/' />
<link rel="alternate" type="application/rss+xml" title="Brian Cray&#039;s Blog &raquo; Delicious.com loses its holy grail Comments Feed" href="http://briancray.com/2009/08/17/delicious-front-page-fails/feed/" />
<meta name="generator" content="WordPress 2.8.4" />

This presents a problem if you

  1. Want to manually mark up your <head>;
  2. And/or want to validate, because much of the markup is invalid;
  3. And/or use HTML5 like I am, because they have closing slashes like so: <tag />

Remove the WordPress <head> junk

If you know enough and you’d like to markup your <head> element yourself, insert this code into the file wp-content/your-theme/functions.php.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
remove_action('wp_head', 'feed_links_extra');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'parent_post_rel_link');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
remove_action('wp_head', 'locale_stylesheet');
remove_action('wp_head', 'noindex');
remove_action('wp_head', 'wp_print_styles');
remove_action('wp_head', 'wp_print_head_scripts');
remove_action('wp_head', 'wp_generator');
 
add_action('wp_head', 'html5_rsd_link');
 
function html5_rsd_link()
{
	echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . '/xmlrpc.php?rsd">' . "\n";
}

If you do this, make sure you manually add these to header.php

  • Stylesheets
  • RSS and/or ATOM links
  • Scripts, if you add them here (I recommend wp_enqueue_script())

Now you have a clean head! =)

After you’ve done this, you’ll regain full control over your <head> element. Isn’t that liberating!?

5 comments skip to comment form

  1. Sean McArthur said— 2 days later

    It’s valid in HTML5 to have self-closing tags. You can write it either way.

    #1
  2. Gary Bishop said— 1 month later

    Thanks. That rel=’next’ link was causing Firefox to repeatedly access posts (I guess it thought it was prefetching) on our literacy site, Tar Heel Reader. Making these changes eliminated that unnecessary load.

    #2
  3. Matthijs said— 6 months later

    Had the same problem! Thanks for this!

    #3
  4. Miguel said— 8 months later

    THANK YOU!!!! I was optimizing using Pagespeed and this lot of garbage was annoying me! I cant simple remove the wp_head call because it had other stuffs!

    #4
  5. Wooguritult said— 11 months later

    asus notebook comparison

    #5
  6. Respond to this post—

Return to navigation
1067