Making Backward Compatible Themes
When creating WordPress themes, one problem I’ve faced is using template tags and other functions which aren’t implemented in older versions of WordPress. Of course the best solution is for people to upgrade their version of WordPress, but you can’t exactly force people to do this. If you want to use new functions, but want to support people with older versions of WordPress, there’s something you can do. As an example, let’s look at wp_page_menu().
Normally you’d call wp_page_menu to get a list of Pages, as well as a link to the home page (providing the home page is not set to a static Page). This function was added in WordPress 2.7, so if you use it in a theme and someone with an older version of WordPress installs that theme, they will get an error. One solution is to check that the function exists before using it, but this gets a bit messy, especially if you use several functions that are new. What do you do when WordPress 23.6 is released? Everyone will most likely have a version of WordPress that supports wp_page_menu, so the check will no longer be necessary. If you are using several functions, you’ll have to go back and fix them in several places throughout the template. This isn’t optimal.
What I’m proposing instead is defining some default action if a given function doesn’t exist. These special definitions can be placed either directly in functions.php, or can be separated into a file specifically intended for them (new_functions.php for example). That way when they’re no longer needed they can easily be removed.
Leave a Reply