Backwards Compatible WordPress 3.0 Functions

We all know that WordPress 3.0 is coming and there are a whole plethora of new features, but actually adding them to themes? I had to do that today in an update to WPShift‘s ShiftNews. Trouble was I wanted to ensure the theme remained compatible with 2.9 and below, which meant I needed some good ol’ conditionals. In this post we’ll find out how to make backwards compatible 3.0 functions.

The problem

You’ve probably heard the “you just need to add one line!!” going around about activating the exciting new features of WordPress 3.0. Whilst that’s true, that is going to mean that your theme requires WordPress 3.0 or above to be run as below this the function won’t be recognised and the page just won’t load. If you’re a responsible theme maker, you know that’d be bad and so obviously want to do something about it to ensure your themes run properly in any of the more recent version of WordPress.

The solution

As I mentioned, the solution is to throw conditionals at the function, in much the same way you’d do it for plugins. The advantage of this is that you can offer a fallback for users who don’t have 3.0 installed; for the menus, for example, you can fall back on list_categories.


First off in your functions.php file wrap each function in

if (function_exists('function-name')) {

For example, for menus it’d be:

if (function_exists('nav-menus')) {

Or for custom backgrounds:

if (function_exists('add_custom_background')) {

And repeat for each function. I did try combining conditionals but that just presented me with a blank screen; if anyone has a solution do let me know.

In the theme

For custom backgrounds that’s all you need to do but for menus, for example, there’s more to do: you’ve got to add the wp_nav_menu function where you want the menu to show up. You’ll need another conditional, this time with an else to provide an alternative for previous versions:

<?php if ( function_exists('wp_nav_menu') ) { //if 3.0 menus exist
wp_nav_menu(array('menu' => 'Header') ); }

else {?>

<ul><?php wp_list_categories('title_li='); ?></ul>

<?php } ?>

It’s that simple

Really, it is. It’s one of those things that you should do to make your theme as compatible as is reasonable (and I think supporting 2.9 is reasonable when the 3.0 upgrade is one that some might wait on because of plugin incompatibilities) and now it’s easy for you to do so there’s no excuse!