Brian Cray ··· Home > Blog > Php, Wordpress > Regain control of your Wordpress head element

Regain control of your Wordpress head element

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>

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

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

Now you have a clean head!

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