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:

<?php wp_head(); ?>

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.

Related posts:

  1. Slow Loading RSD URLs In WordPress
  2. Adding XML-RPC Methods to WordPress
  3. WordPress 2.9 – XML-RPC and AtomPub Changes
  4. I Don’t Like PHP’s extract() Function
  5. WordPress 2.7.1 Released – XML-RPC and AtomPub Changes

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

11 Comments »

 
  • Is it the or the that pulls in WordPress.com stats?

  • My code markup go stripped… Is it the wp_head or wp-footer that pulls in stats?

  • Matt Martz says:

    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.

  • Thom Allen says:

    Will using wp_head() cause any styling issues? or is it simply giving the theme access to internal WordPress functionality?

    • Joseph Scott says:

      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.

  • [...] some more searching, I found this website which helped me fix my problem.  For Counterize II to function, you have to [...]

  • Ryan Ray says:

    Thank you!! You fixed my problem! I had edited my Header and took the tag out

  • Jue says:

    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.

  • [...] versteckten Felder im Kommentarbereich – was nach einem CSS Problem riecht – wobei der gängige Grund bei Problemen mit bestimmten Themes <?php wp_head(); [...]

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>