Categories
Posts

WordPress Theme Authors, Don’t Forget The wp_head() Function

When creating a WordPress theme don’t forget to include a wp_head(); call in the HTML HEAD section of your theme. It’s very simple to do, just include:

[sourcecode lang=”php”]
wp_head();
[/sourcecode]

Before the closing HEAD tag (</head>) in your HTML.

Why make such a fuss over a single function call? Because it does a fair bit of work behind the scenes and without it some WordPress features will not work properly. Take a look at the wp_head section of the wp-includes/default-filters.php file in WordPress, you’ll see a number of events that are tied to the wp_head action.

One area where this is a particular problem is for offline blog clients that make use of the XML-RPC and AtomPub APIs in WordPress. The “Really Simple Discoverability” (RSD) link that WordPress inserts instructs these clients on where to find the RSD URL, which contains information on how the clients can send XML-RPC and AtomPub requests. We’ve seen a number of times now where an error reported by a WordPress iPhone App user is caused because there is no RSD link in their WordPress blog. Looking a little deeper reveals that there was no RSD link because the theme they were using didn’t include a call to wp_head().

If you are writing a WordPress theme here is your reminder, make sure that the wp_head() function is being called at the end of your HEAD section.

15 replies on “WordPress Theme Authors, Don’t Forget The wp_head() Function”

With 2.8 adding the functionality to enqueue scripts into the footer, as well as this is where the wp.com stats plugin puts the tracking code, theme authors need to remember to include wp_footer() also.

I don’t think any of the default actions (see wp-includes/default-filters.php) will change the styling at all. Any theme that doesn’t call wp_head() should be considered broken. There are core features of WordPress that require it in order to work. In addition to RSD there’s: wp_enqueue_scripts (makes sure the correct Javascript files get included in pages), WLW manifest file (tells Windows Live Writer what features WP supports) and comment threading Javascript. That isn’t a complete list, just the highlights.

There are also plugins that make us of wp_head() as well.

Thank you, this cleared up a problem I had with the WP-Polls plugin. I had removed BOTH wp_head and wp_footer from my template a long time ago when I knew much less about theming, and only recently have begun to pay for it with mysterious plugin problems. This warning should be emblazoned on EVERY beginner themer’s guide out there.

wp_head makes my site very slow. In average, 2.5 seconds on 3.6 needed for the whole page.
I’ve removed action in wp_head (may be the list useful) but i can’t resolve this problem.
Any ideas ?
Best regards from Paris, France

I am still unable to get this to work on my blog site. The area for the sidebar shows up. But the actual sidebar doesn’t. I have an area for designating the widget areas and have activated use of sidebar (Posts) in post and pages. I have tried putting
[sourcecode lang=”php”]
wp_head();
[/sourcecode]

in the header and the code actually shows up in the header. What amd I doing wrong?

Leave a Reply

Your email address will not be published. Required fields are marked *