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

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.

22 Responses

Nov 13 2008 15:15

This is a much needed piece of code for the coming wp 2.7!

Nov 13 2008 20:33

Awesome! Just in time before I make the move to WP 2.7 but then I’m using the Brian’s threaded comment right now. Does it have any effect? Do I need to make additional changes?

Yan

Nov 13 2008 20:45

@Blog for Beginners: Sadly, I don’t know this plugin, so I can’t answer you :( But normally you’ll not need this plugin anymore one WP 2.7 will be released.

Nov 13 2008 21:29

I do understand that you don’t need it anymore as threaded comment comes with the package. But the whole comment.php has been changed to make way for Brian’s so I’m still not too sure about it.

Anyway, thanks buddy. Not an issue at the moment.

By the way, do you know how to make category links “nofollow”?

Yan

Nov 14 2008 05:02

I made a promise to myself not to put 2.7 at least after a month of its release….

Dec 26 2008 20:55

Im a big fan of this blog. But, i can´t understand about the change in the comments template.

Regards!

Maxi Sanchez

Dec 27 2008 18:53

I need a little help,

i use wp 2.7 and my theme is not compatible with this option, threaded comments, what i need to change to work?

Thanks

Dec 29 2008 04:02

Dodo, maybe you need to go on your Admin Panle > Discussions > and “active the comments options”.

Good Luck, soory about my english :D

Regards,

Maxi Sanchez

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required