How to: make your comments template compatible with WordPress 2.7 and older versions

November 11, 2008 at 8:09 am

Some days ago, I shown you how to make your comments template compatible with WordPress 2.7. If you’re a theme designer, you’ll probably be interrested to know how to ensure backward compatibility with older versions.

To achieve this recipe, you’ll need two file: The first one is a WordPress 2.7 compatible comments file, named comments.php. The second one is a comment template for older WordPress versions, named legacy.comments.php in this exemple.

Paste this elegant code in your theme functions.php file. Create this file if it do not exists yet. If the wp_list_comments() function doesn’t exists, the code will automatically load legacy.comments.php instead of comments.php.

<?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;
}
?>

Thanks to Justin Tadlock for this awesome code.