Making your theme's comments compatible with WordPress 2.7 and earlier versions
I’ve been working hard on a new WordPress theme, but I needed the theme to be compatible with both WordPress 2.6 and 2.7.
If you’re a theme developer, you already know how hard it’s going to be to make your 2.7 theme backward compatible because of all the new features being added.
I won’t go into the details of how to put together a comments.php
file here. There are plenty of tutorials and themes to look at for that.
Check out Otto’s WordPress 2.7 comments enhancements tutorial to add all the extra features to your theme’s comments file.
Setting up the comment files
Let’s assume you start with a WordPress 2.6-ready comments file. What you need to do is save that file as legacy.comments.php
in your theme directory.
Next, you need to create your WordPress 2.7-only comments file and save it as comments.php
.
What we’ll be doing is checking the version of WordPress the theme user has installed. If they’re using 2.7, we’ll call comments.php
. If they’re using 2.6 or below, we’ll use legacy.comments.php
.
In your theme’s functions.php
file, add this code:
<?php
add_filter('comments_template', 'legacy_comments');
function legacy_comments($file) {
if(!function_exists('wp_list_comments')) : // WP 2.7-only check
$file = TEMPLATEPATH . '/legacy.comments.php';
endif;
return $file;
}
?>
That’s it. All we did was filter the comments_template
.
So, if you’re looking to add a little backward compatibility to your WordPress theme, this should help a bit.