WordPress 2.3 Theme Backward Compatibility
Over at BlogginPro, the question was posed:
My biggest question is “what will happen if we take the newly updated theme, and place it on a blog running a previous version of WordPress?”
Is there some way to check which version of WordPress is being run, or will we have to put out a WordPress 2.3 only version of each and every theme?
I’m not normally an active commenter on blogs, but since I knew the answer to the question, I figured I’d speak up and answer the question. Because of this, I figured I’d go ahead and answer it here as well.
PHP comes with the built in capability to check to see if a function exists. Since template tags are nothing more than PHP functions, it makes sense that you can very easily use the function_exists condition to check the availability of the function before actually calling it. It would go a little something like this:
<?php if ( function_exists('the_tags') ) {
the_tags('Tags:', ', ', ''); } ?>
So now, you have added the ability to add tags to your theme, without breaking it in all versions prior to 2.3.
Bonus Tip
OK, I have to admit that I haven’t actually done this for my themes, but I wanted to throw this out there as a possibility. If you’ve been developing themes for a while now, you’ve got to be aware of tags that have been deprecated. For instance, let’s say you wanted to list your categories in the sidebar. Normally, you would use the wp_list_categories function.
But if you wanted to be backward compatible, you would use the deprecated tag (wp_list_cats) instead of the new one. That way, you make sure you have a catch-all function (since WordPress doesn’t remove deprecated functions from the code for quite a while).
In reality, you’re using an inferior function, even if the user has a fully upgraded version of WordPress.
It would be better if you used the function check to make sure your theme is truly, fully backward compatible. That means that even after WordPress phases out the deprecated function, your theme still works.
This also eliminates the need to release different themes for different versions of WordPress. A single theme will work universally! Here’s a sample of how you would do it:
<?php if ( function_exists('wp_list_categories') ) { //if the new function exists
wp_list_categories(); } else {
wp_list_cats(); } ?>
Easy as cake! Enjoy your new, fully backward compatible theme!
The Tags: no tags






8 Responses to “WordPress 2.3 Theme Backward Compatibility”
Hi Nathan,
Comment made on October 19th, 2007 at 6:00 pmThanks for the code tip! Now… where do I input it (which .php theme page?)
Thanks,
Gilles
Gilles,
Comment made on October 20th, 2007 at 12:29 pmI put the code in the index.php, archive.php, and single.php files. The placement is up to you though.
I didn’t expect WP 2.3’s tagging functionality to cause problems with themes, but sure enough a theme I released last week has caused ‘undefined function’ havoc for some users. That if-statement is a good tip - thanks!
Comment made on October 20th, 2007 at 6:53 pmDarren,
Comment made on October 23rd, 2007 at 7:18 amMy pleasure! Glad it helped!
Thanks for the code tip!
Comment made on February 9th, 2008 at 10:32 amThanks
Trackbacks
[...] Find this code at Nathan Rice - http://www.nathanrice.net/blog/wordpress-23-theme-backward-compatibility/ [...]
Comment made on October 13th, 2007 at 3:13 am[...] Rice covers how to make your WordPress Theme backwards compatible to accommodate the new tags, and how to customize WordPress Tag tags on Themes. You can find more [...]
Comment made on October 26th, 2007 at 5:39 am[...] to download buggy and vulnerable Themes. Those who upgraded are stuck with Themes that aren’t WordPress 2.3 compliant. WordPress 2.4 is due out next month, which may include more changes to WordPress Themes, making [...]
Comment made on December 11th, 2007 at 10:06 amLeave a Comment