Enabling Comments on Every Wordpress Page

Sat, May 17, 2008 (Technology)

Ok this might seem trivial to the smarter WordPress folks out there, but I’m dumb… dumb like a sack of rocks and didn’t just figure this out until now.

If you’ve been using WordPress for years and always wondered why the ‘Add a Comments’ section only show up on the front page of the blog and nowhere else BUT the admin interface and the rest of WordPress seem to happily support comments on every page then you are in luck.

As it turns out most (if not all?) themes I’ve used for WordPress do not include the comment-enabling snippet of code on the default Page template that is used to render sub-pages of the main site (for example, on this site, like the Contact, About, Reviews, etc. sections).

The trick is to edit the Page template of whatever theme you are using and add the following snippet of code right below the existing post-div (ends with comment: <!–/post–>)

So find that section and right after it, add this new comments div:

<div id="comments" class="box2">
    <?php comments_template(); ?>
</div>

You are now set, every single page on your site will include the Comments section template, and since WordPress already supports pages having comments, there is nothing more to do… it will just suddenly work.

You can see this in action (as an example) over on the kallasoft SmugMug Java API Examples page.

Hope that helps some of you WordPress’ers out there.

  • Facebook
  • MySpace
  • Digg
  • StumbleUpon
  • Reddit
  • Tumblr
  • Mixx
  • Propeller
  • FriendFeed
  • Suggest to Techmeme via Twitter
, ,

This post was written by:

Riyad Kalla - who has written 1758 posts on The “Break it Down” Blog.

"Ultimately I just want to provide a resource that folks find useful."

Contact the author

25 Responses to “Enabling Comments on Every Wordpress Page”

  1. Alexander Says:

    Thanks, I just didn´t know how to do it. Now I do. (Big relieve, because other advices could´t help me further). Once again, thanks for sharing. Regards, Alexander

    Reply

  2. Editor Says:

    No problem Alexander, glad it helped.

    Reply

  3. Muirshin Durkin Says:

    Ah, after trying a few other potential solutions, this was the one that did the trick. I really needed comments to work on my pages; thanks a bundle!

    Reply

  4. Riyad Kalla Says:

    Muirshin,

    That’s great news, I’m glad it helped.

    Reply

  5. Christy Says:

    Keep a good work man!,

    Reply

  6. Helen Says:

    Aw, man. The code technically works, but it screws up my side bar. That sucks! Thanks, though. :)

    Reply

  7. Riyad Kalla Says:

    Helen,

    I went to your website, the layout looks pretty standard (I wouldn’t expect the comment block to screw up the sidebar). Are you sure you added the code in the right place?

    Reply

  8. John Says:

    Thanks man, worked great. Found this post in a Google search. Tried a different one and it didn’t work, your explanation took 45 seconds to implement and I was up and running. Really appreciate it.

    Reply

  9. BAM Says:

    how do you remove it from themes that already have it?

    Reply

  10. Sergio Says:

    Hello,
    I have enabled it in every page.

    Now how is it possible to disable it from 1 page only?

    Or maybe the opposite – to enable it on one page only?

    Thanks

    Reply

  11. Riyad Kalla Says:

    Sergio,

    You can check the WP API codex and find the variable that is set when comments are enabled on a page, and then wrap that code-block with a conditional in the template editor, so depending on if you set the comments enabled in the admin interface or not, that code block that renders comments is either shown or not shown.

    Most themes support that anyway, so on that page try and disable comments (it’s under the post content box) and see if it disappears.

    Reply

  12. Ramon Says:

    Men you saved my life. Keep up the good work.

    Reply

  13. Jun-G Says:

    Thanks man, been looking for this solution. It really helped me a lot.
    You rock!

    Cheers!

    Reply

  14. Ivan Says:

    Thank you! A big mystery cleared up …

    Ivan

    Reply

  15. TheNightOwl Says:

    Hey, Riyad

    Thanks VERY much for this. Really.

    I, too, am as dumb as a box of hammers with this kind of stuff. (Although, just quietly, between you’n'me… I really AM as dumb as a box of hammers with all this stuff and you, my friend, are NOT!)

    =)

    I just reinstalled a site and wanted to transfer all posts to Pages. This sorted it out very quickly and easily in my Theme.

    Thanks again,
    TheNightOwl

    Reply

  16. Gavin Says:

    Sorry for asking a Dumber question .
    But Where exactly do I insert this ?
    Is it in the comment.php or index.php of the default theme

    Reply

    • Riyad Kalla Says:

      Gavin, not a dumb question at all — it’s in the Page template, usually page.php or something like that — you just pop the snippet in there and then standard pages (rendered using the ‘page.php’ file) will show the comments box!

      Reply

  17. Saidul Says:

    O man I am really appreciate you save my 50 bucks. I was going to hire some one but I found that. thanks again

    Reply

  18. MarkmafiawarsCheats Says:

    Thanks for the code!

    How about comments on front page? I cannot find any help with this. I get comments on secondary pages only.

    Reply

  19. Vikas Gupta Says:

    I just shifted from wordpress.com to .org and did the trick. The comment box shows but how to show the comments on each page that were already there??!! Thanks a lot for help.

    Reply

  20. kiezel Says:

    I just added the code to index.php (but couldn’t find the right location), because I don’t have a page.php but it didn’t help..

    Reply

  21. Lisy Says:

    It worked, but I’m getting the following (right below the comment box):

    XHTML: You can use these tags:

    How do I get rid of that XHTML?

    Reply

  22. Riyad Kalla Says:

    Lisy,

    Dollars to donuts that your theme is the one styling your “comments” code block to look like that. So wherever you tell wordpress “insert the comment box here” that comes in with it.

    If you login to the admin panel, go to Appearance > Edit, then select the “comments.php” template, I bet that text will be in there. If you remove it, you will no longer see it.

    If you aren’t familiar with HTML you will likely see junk like “<” and “>” instead of a clear-cut a-href link… that’s just because they are using the character-codes for ‘less than’ and ‘greater than’ (respectively) so instead of rendering an actual link, it shows you the text FOR a link.

    Hope that helps!

    Reply

Trackbacks/Pingbacks

  1. Fernando E - 22. Mar, 2009

    http://tinyurl.com/67r8te i heart learning something new everyday. Comments for the masses!

Leave a Reply