If you had viewed the source of my WordPress-generated pages a while ago you'd have noticed that my head elements were a real mess. Now they've been spring cleaned, arranged neatly into related groupings and the needless clutter disposed of. Plugins that use the wp_head hook distribute junk all over the show, offending any sense of order. Luckily your WordPress theme is the key to taking control of your head, through a combination of edits to functions.php and header.php.
Removing actions using a functions file
Your theme may already include a file called functions.php. If it doesn't you can create one using the functions file found in the default theme directory (which is a bit busy), or copy-and-paste mine (with the K2 bits stripped out for clarity):
<?php
// De-clutter wp-head
// Really Simple Discovery
remove_action('wp_head', 'rsd_link');
// Windows Live Writer
remove_action('wp_head', 'wlwmanifest_link');
// Quoter plugin
remove_action('wp_head', 'quoter_head');
// wp-forecast plugin
remove_action('wp_head', 'wp_forecast_css');
// K2 custom header
remove_action('wp_head', array('K2Header', 'output_header_css'));
?>
The real advantage here is avoiding the need to hack any plugins or core WordPress files (an upgrader's nightmare). Let's go through the removal actions in sequence.
Really Simple Discovery helps client software discover things about your blog. If you don't use a client and manage your posts directly in WordPress, you don't need to offer such help. The PHP script:
remove_action('wp_head', 'rsd_link');
will remove a line from your head that looks something like this:
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.bioneural.net/xmlrpc.php?rsd" />
Windows Live Writer is one such desktop blogging client, but supporting it needs yet another line in your head. The script:
remove_action('wp_head', 'wlwmanifest_link');
will remove a line from your head that looks something like this:
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.bioneural.net/wp-includes/wlwmanifest.xml" />
The Quoter plugin defaults to inserting comments, JavaScript, and CSS into your head:
<!-- Added by Quoter plugin v1.1 -->
<script type="text/javascript" src="http://www.bioneural.net/wp-content/plugins/quoter/quoter.php?js=1"></script>
<style type="text/css" media="screen">
.commentlist blockquote cite { /* Fix for Kubrik theme */
display: inline;
}
</style>
You don't need that inline CSS if you're not using Kubrik, and can remove it with this script in functions.php:
remove_action('wp_head', 'quoter_head');
You can then restore functionality with a much tidier JavaScript call in an appropriate place (moving any custom CSS to your CSS file):
<script type="text/javascript" src="http://www.bioneural.net/wp-content/plugins/quoter/quoter.php?js=1"></script>
The wp-forecast plugin insists on inline CSS too. The script:
remove_action('wp_head', 'wp_forecast_css');
will remove a line from your head that looks something like this (again, any CSS goes in your CSS file):
<link rel="stylesheet" href="http://www.bioneural.net/wp-content/plugins/wp-forecast/wp-forecast.css" type="text/css" media="screen" />
The K2 theme inserts some particularly messy inline CSS:
<style type="text/css">
#header h1 a, #header .description {
color: #ffffff;
}
</style>
We can ditch this if not using custom K2 headers as follows:
remove_action('wp_head', array('K2Header', 'output_header_css'));
Finding the right function that adds the action can involve a bit of trial-and-error. Searching plugin (or theme) code for a partial match to an unwanted string appearing in your head is a reasonable first option.
The plugin alternative
The Codex describes the functions file as being "like a plugin". This turns out to be quite literal; you could take the above functions and roll your own plugin (as suggested here). Create a file (head-cleaner.php say) containing the actions you want removing (your list may differ from mine), upload it to /wp-content/plugins/ and activate it in the usual way:
<?php
/*
Plugin Name: Head cleaner
Description: Removes unwanted clutter from the head.
*/
// Really Simple Discovery
remove_action('wp_head', 'rsd_link');
// Windows Live Writer
remove_action('wp_head', 'wlwmanifest_link');
// Quoter plugin
remove_action('wp_head', 'quoter_head');
// wp-forecast plugin
remove_action('wp_head', 'wp_forecast_css');
// K2 custom header
remove_action('wp_head', array('K2Header', 'output_header_css'));
?>
Other head-cleaning tips
Have a poke around in your theme's header.php file, and see if you can organise it a bit better.
I also found I could remove the following, found in the header.php of many themes, with no adverse effects:
<?php wp_get_archives('type=monthly&format=link'); ?>
This script produced a whole bunch of lines in the head having the following form:
<link rel='archives' title='January 2008' href='http://www.bioneural.net/2008/01/' />
Removing the lengthy relative links list for archives doesn't seem important except in theory:
The rel="archives" does not have any specific use that I am aware of. It is used to define other pages that are archives of the site in question. In other words, it's defining pages where the content on this page will be seen in the future.
Finally, some plugins may insert code that, while not necessarily disorderly, may not be just the way you like it. For example, Simple Tags can automatically insert keyword metadata into the head of each and every page. You might feel, however, that it's not sensible to associate metadata with a dynamic index page that temporarily contains tagged posts on a variety of topics. You could therefore make metadata insertion conditional, using Simple Tags manually as follows:
<?php if ( function_exists('st_meta_keywords') and is_single() ) { ?>
<?php st_meta_keywords(); ?>
<?php } ?>
Alternatively, if you shun dependence on plugins you may want to use built-in WordPress functions, as detailed here:
<?php /* Get the meta keywords */ global $post;
if( is_single() || is_page() ) :
$tags = get_the_tags($post->ID);
if($tags) :
foreach($tags as $tag) :
$sep = (empty($keywords)) ? '' : ', ';
$keywords .= $sep . $tag->name;
endforeach;
?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<?php
endif;
endif;
?>
It looks like a lot more code, but remember it will still produce just the one line meta element.
That's enough. Too much of this sort of thing cleanly clearly does my head in.











Thank you thank you!! I was about to hack into 4 different plugins that were unnecessarily loading CSS and JS on every page and slowing my site way down and you helped me solve my problem. Gracias.
Hey, thanks for sharing this. I'm doing a little spring cleaning myself, and this is exactly what I was looking for. Extremely helpful. Thanks!
Thanks for this post! I have been trying to change the header text color in my K2 style, but finally found out this lame embedded style sheet was overriding it.
Great post, mess in my header was causing my site to load VERY slowly. The use of this post and a page speed debugger got me to the answer and solution.
Much appreciated.
n
Wow, great post on setting the wp-head on diet. Still relevant and much appreciated, Thanks!
Thanks for this, it seems to work for everything except the inline styles!!
I have remove_action('wp_head', array('K2Header', 'output_header_css')); as above but the inline #header css styles are still present !!??