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.

Other resources

58 responses to “Making your theme’s comments compatible with WordPress 2.7 and earlier versions”

  1. Mayur Somani

    Thanks a lot!

    Can you please share some of the other issues which must be kept in mind while working on themes that are both 2.6 and 2.7 compatible.

    Thank you for your time.

  2. Justin Tadlock

    This was the biggest issue. There are some things you can’t get around if you decide to use the new features as implemented in the Default theme, such as post_class(). You’d have to implement your own function to replace it.

    The next big one would be wp_page_menu() to list a navigation menu of pages. I’ll probably cover that in the next tutorial.

  3. Mayur Somani

    That would be great!!
    Thanks.

  4. BoltClock

    It looks like I’m going to have to start work on BoltPress 2.1’s code soon. I can’t bear to part with my really awesome 2.0 design so I’ll just recode it for WordPress 2.7.

    I also have Thistle to worry about, and I’m not even sure about my Sandbox designs anymore :S

  5. Lyndi

    Just when I thought I was going to need long conditional tags. Thanks for this.

  6. J Mehmett

    Great tip, Justin. Thank you very much.

    WP2.7 messed many things from the front end (Theme) to the admin panel.

  7. Nathan Rice

    Wow, this is SO strange. This is almost EXACTLY the same method I employed 2 weeks ago to make a future free theme of mine 2.5-2.7 compatible.

    Great minds think alike, eh? :-)

  8. Otto

    That’s a pretty clever approach that I had not considered. Nice and clean.

  9. Justin Tadlock

    BoltClock
    I know what you mean with updating themes. I’ve got four other major themes that must be updated.

    Lyndi
    This will definitely cut back on all those conditional tags and function_exists() checks. You’ll only have to use one conditional with this method.

    J Mehmett
    Yeah, there are some major changes in 2.7 that have to be considered from both a frontend and backend perspective. Things are better, but there’ll be a lot of backward compatibility issues.

    Nathan
    I’m thinking they do think alike. ;)

    I’m actually making my theme 2.5 - 2.7 compatible but said 2.6 in the post for simplicity. Filters make WordPress such an easy platform to customize.

    Otto
    “Nice and clean” was exactly what I was going for. I had so many conditional tags it was starting to get ridiculous. After my comments.php file soared up to over 7kb, I knew I needed a better method.

  10. Weekly Links #25 | GrantPalin.com

    [...] Making your theme’s comments compatible with WordPress 2.7 and earlier versions Good to know, what with the approaching release. [...]

  11. WordPress 2.7 Comments Enhancements

    [...] of the more interesting ways I’ve seen to use this is to have the “old comments” php in a separate file [...]

  12. How To: Make Your Comments File Compatible with WordPress 2.7 | WordPress Hacks Log

    [...] Are you looking to make your WordPress installation compatible with WordPress 2.7?   Justin Tadlock recently featured a great post explaining how to make your theme’s comments compatible with WordPress 2.7. [...]

  13. Jauhari

    Wow, thanks for sharing Justin.. it’s perfect

  14. WordPress 2.7 Updates — WPCandy — WordPress Themes, Plugins, Tips, and Tricks

    [...] survey regarding all the new features of WordPres 2.7, where you can provide additional feedback. - Make your themes comments compatible with WordPress 2.7 and earlier versions. - WordPress 2.7 Comments Enhancements: An in-depth post on the changes WordPress 2.7 brings to [...]

  15. All you wanted to know about WordPress 2.7 | Featured | WereWP

    [...] In this latest release you will be able to have threaded and paged comments, like on Digg. Well, you got it by yourself, that means a bit of work for developers while adapting your own WordPress theme to the new comment system. Can you do that? Yes, thanks to the great tutorial by Otto! Justin Tadlock has also proposed us a method to create a WordPress 2.6 and 2.7 compatible theme! [...]

  16. The Ambuscade

    [...] Making your theme’s comments compatible with WordPress 2.7 and earlier versions (tags: obeertym) [...]

  17. Justin Tadlock

    Jauhari
    No problem. I’m hoping we can get most theme developers to update their comments for 2.7 but still allow for those users that upgrade a little later (you know, the [dot] 1 crowd).

  18. Paleo Pat

    Anyone wanna edit my theme? I’m clueless.

    -Pat

  19. Justin Tadlock

    Paleo Pat
    You can use my contact form if you’re interested in hiring me to do any work on your theme.

  20. Links for 4th November 2008 | Velcro City Tourist Board

    [...] Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  21. Are your theme’s comments WordPress 2.7 compatible? | Wordpress Blog NL

    [...] Making your theme’s comments compatible with WordPress 2.7 and earlier versions.: If you are a theme designer or author, you need to know that your legacy theme’s comments page will not be compatible with WordPress 2.7 Justin Tadlock has written up a simple (and clean) procedure to make the comments page compatible with WordPress 2.7 and still be backwards compatible with slightly older version of WordPress. [...]

  22. Ajustando seu tema para o Wordpress 2.7 | bernabauer.com

    [...] manter o tema compatível com o 2.7 e com o 2.6 o bacana é ver este artigo. Já para entender as alterações necessárias no tema para usar o [...]

  23. WordPress 2.7 Comment Template | Pinoy Teens

    [...] Comment Template and the features it brings like Comment Paging, Comment Threading and even more.Make your Comment Templates 2.7 and backwards compatibleDetailed Post about adding the Comment [...]

  24. Are your theme’s comments WordPress 2.7 compatible? | BlogBroker24-7

    [...] Making your theme’s comments compatible with WordPress 2.7 and earlier versions.: If you are a theme designer or author, you need to know that your legacy theme’s comments page will not be compatible with WordPress 2.7 Justin Tadlock has written up a simple (and clean) procedure to make the comments page compatible with WordPress 2.7 and still be backwards compatible with slightly older version of WordPress. [...]

  25. Tips on How to get ready for WordPress 2.7 | Earning Money Online Guide and Tips - davcheong - Blog Tips Help On How I Make Money Online ::

    [...] reference of how to enhance your comments file, from Justin Tadlock’s early preparation for 2.7 and Otto’s WordPress 2.7 Comments [...]

  26. Are your theme’s comments WordPress 2.7 compatible | PATRONIT.NET

    [...] Making your theme’s comments compatible with WordPress 2.7 and earlier versions.: If you are a theme designer or author, you need to know that your legacy theme’s comments page will not be compatible with WordPress 2.7 Justin Tadlock has written up a simple (and clean) procedure to make the comments page compatible with WordPress 2.7 and still be backwards compatible with slightly older version of WordPress. [...]

  27. WordPress 2.7 Threaded Comments

    [...] I have been asked by many people if my Revolution themes will be updated to accommodate WordPress 2.7 and Threaded Comments. The answer is yes, with thanks to a few lattes, 2 1/2 hours and posts that I’ve read from Otto and Justin. [...]

  28. Weblog Tools Collection: Are your theme’s comments WordPress 2.7 compatible? | Aslifm Blogu

    [...] Tools Collection: Are your theme’s comments WordPress 2.7 compatible? Kas.08, 2008 in WP-RSS Making your theme’s comments compatible with WordPress 2.7 and earlier versions.: If you are a theme designer or author, you need to know that your legacy theme’s comments [...]

  29. WordPress Wednesday News: WordPress 2.7 Beta 2, Danger WordPress Faker, and More WordCamps | The Blog Herald

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  30. WordPress 2.7 News « Lorelle on WordPress

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  31. Lorelle on WP: WordPress 2.7 News | Aslifm Blogu

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

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

    [...] to Justin Tadlock for this awesome [...]

  33. digitalrendezvous | blog - Crazy Horse

    [...] really nice information for themecreators or people who made their own theme can be found here at justintadlock.com and here at ottodestruct.com [...]

  34. Wordpress 2.7 Checklist

    [...] Making your theme work in both 2.7 and other versions [...]

  35. WordPress 2.7 Updates | Mamma Mac.com

    [...] survey regarding all the new features of WordPres 2.7, where you can provide additional feedback. - Make your themes comments compatible with WordPress 2.7 and earlier versions. - WordPress 2.7 Comments Enhancements: An in-depth post on the changes WordPress 2.7 brings to [...]

  36. WordPress Wednesday News: 2.7 Delayed, Sneak Peak Video, Help WordPress iPhone, WordCamps | The Blog Herald

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  37. Pribesagtiese

    i want to share my free wordpress theme here.

    Deleted by admin.

  38. Justin Tadlock

    Yeah, posting links to your site in an inappropriate place is the quickest way to get them deleted.

  39. 泉州生活网

    顶~~~~我叫泉州生活网,希望能交个朋友哈!

  40. WordPress Wednesday News: Beta 3 Released, WordCamp Australia, No WordPress 2.6.4, and More | The Blog Herald

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  41. 让 WordPress 主题评论模板同时兼容 WordPress 2.7 及早期版本 - WordPress 非官方中文站

    [...] 原文:Making your theme’s comments compatible with WordPress 2.7 and earlier versions by [...]

  42. WordPress News: WordPress 2.7 New Login, WordCamp Australia, WordPress 2.6.5 Security Update, BuddyPress, and More | The Blog Herald

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  43. WordPress 2.7 Release News and Links « Lorelle on WordPress

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  44. Shanker Bakshi

    What about the avrious themes that you offers?

  45. Gestion des commentaires pour wordpress 2.6 et wordpress 2.7

    [...] convient de préparer le changement de version pour son template. Justin Tadlock nous explique dans Making your theme’s comments compatible with WordPress 2.7 and earlier versions comment s’y préparer : par l’ajout tout simple d’une petite fonction de filtre [...]

  46. Justin Tadlock

    Shanker
    What do you want to know about the themes that I offer?

  47. showgirl » Blog Archive » 让 WordPress 主题评论模板同时兼容 WordPress 2.7 及早期版本

    [...] 原文:Making your theme’s comments compatible with WordPress 2.7 and earlier versions by [...]

  48. WordPress 2.7: Personnaliser l’affichage des commentaires - Emmanuel GEORJON

    [...] troisième solution, proposée par Justin TadLock me semble la plus [...]

  49. Come rendere compatibile il vostro vecchio tema con wordpress 2.7 | Pillole
  50. WordPress 2.7 Upgrade Tips « Lorelle on WordPress

    [...] My WordPress Theme Will Break: There is very little that will impact WordPress Themes in this new version, outside of WordPress Plugins that interact with WordPress Themes, especially with comments. WordPress Themes will be even better protected in future versions with the Parent/Child Theme feature (your changes are protected during upgrades) and easy auto-updating of Themes. If your Theme features customization to the comments area, see Migrating Plugins and Themes to 2.7 and Justin Tadlock’s “Making your theme’s comments compatible with WordPress 2.7 and earli…. [...]

  51. WP 2.7 Blog Party is ON! | Human3rror - Where Typos are Part of the Equation

    [...] Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions [...]

  52. Separating Comments and Trackbacks in WordPress - The Answer « Lorelle on WordPress

    [...] News: For information on the new structure of comments and trackbacks in WordPress 2.7, please see Justin Tadlock - Making your theme’s comments compatible with WordPress 2.7 and earlier versions and Sivel - Separating Pings from Comments in WordPress [...]

  53. Lorelle on WP: WordPress 2.7 Upgrade Tips | Aslifm Blogu

    [...] My WordPress Theme Will Break: There is very little that will impact WordPress Themes in this new version, outside of WordPress Plugins that interact with WordPress Themes, especially with comments. WordPress Themes will be even better protected in future versions with the Parent/Child Theme feature (your changes are protected during upgrades) and easy auto-updating of Themes. If your Theme features customization to the comments area, see Migrating Plugins and Themes to 2.7 and Justin Tadlock’s “Making your theme’s comments compatible with WordPress 2.7 and earli…. [...]

  54. WordPress 2.7 Upgrade Tips | Make Money From Blog

    [...] My WordPress Theme Will Break: There is very little that will impact WordPress Themes in this new version, outside of WordPress Plugins that interact with WordPress Themes, especially with comments. WordPress Themes will be even better protected in future versions with the Parent/Child Theme feature (your changes are protected during upgrades) and easy auto-updating of Themes. If your Theme features customization to the comments area, see Migrating Plugins and Themes to 2.7 and Justin Tadlock’s “Making your theme’s comments compatible with WordPress 2.7 and earlier versi…. [...]

  55. WordPress 2.7 技巧、插件与资源精选 - WordPress 非官方中文站

    [...] Making Your Theme Comments Compatble with 2.7 & Earlier Versions(让你主题兼容WordPress 2.7 和以往版本) Justin Tadlock 讨论的这个很好的话题,告诉我们如何让你的主题同时兼容 WordPresss 2.7,并能回溯兼容早期版本。适合主题开发者。 [...]

  56. Sarah

    Thanks so much for this.
    I’d like to second Mayur Somani’ request to please share also other issues which must be kept in mind while working on themes that are both 2.6 and 2.7 compatible.

  57. dodo

    Hello,

    I have install wp 2.7 but the theme is not compatible with threaded comments and i add the up code in functions.php from theme and change from legacy.comments.php sin comments.php but i don t see a change in my post comments. What is wrong what i need to do more?

    Thanks

  58. Justin Tadlock

    Sarah — This is the major thing you have to watch out for. Check out the WordPress Codex for a complete list of changes.

    dodo — This isn’t a tutorial on making threaded comments work. This is a tutorial for theme developers that want to add backward-compatible comments. You should go to the WordPress.org support forums if you need help setting yours up or ask your theme author.

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.

WordPress-o-Sphere