Enabling Comments on Every Wordpress Page

Updated August 2010

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 (file is typically page.php) 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>

Update #1: The important thing here is the “<?php comments_template(); ?>” code snippet; you can actually add that anywhere you want the comment box to popup in your page inside the main content loop, it doesn’t necessarily need to be inside a comment div or after the post. That is just typically where it is placed.

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.

Tags: , , , , ,

This post was written by:

Riyad Kalla - who has written 2270 posts on The Buzz Media.

Software development, video games, writing, reading and anything shiny. I ultimately just want to provide a resource that helps people and if I can't do that, then at least make them laugh.

Contact the author

41 Responses to “Enabling Comments on Every Wordpress Page”

  1. Alexander 11. Aug, 2008 at 2:20 pm #

    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

  2. Editor 11. Aug, 2008 at 4:30 pm #

    No problem Alexander, glad it helped.

  3. Muirshin Durkin 30. Oct, 2008 at 1:04 am #

    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!

  4. Riyad Kalla 01. Nov, 2008 at 9:34 am #

    Muirshin,

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

  5. Christy 04. Nov, 2008 at 11:16 am #

    Keep a good work man!,

  6. Helen 08. Nov, 2008 at 6:17 pm #

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

  7. Riyad Kalla 09. Nov, 2008 at 8:24 am #

    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?

  8. John 07. Apr, 2009 at 12:02 pm #

    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.

  9. BAM 06. Jun, 2009 at 11:15 am #

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

  10. Sergio 15. Jun, 2009 at 2:23 pm #

    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

  11. Riyad Kalla 16. Jun, 2009 at 5:02 pm #

    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.

  12. Ramon 01. Jul, 2009 at 8:30 pm #

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

  13. Jun-G 29. Jul, 2009 at 9:19 pm #

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

    Cheers!

  14. Ivan 15. Sep, 2009 at 6:12 am #

    Thank you! A big mystery cleared up …

    Ivan

  15. TheNightOwl 23. Oct, 2009 at 5:54 am #

    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

  16. Gavin 27. Oct, 2009 at 1:40 pm #

    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

    • Riyad Kalla 28. Oct, 2009 at 11:00 pm #

      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!

      • Saqib 06. Aug, 2010 at 3:59 pm #

        good post

  17. Saidul 16. Nov, 2009 at 8:47 pm #

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

  18. MarkmafiawarsCheats 24. Nov, 2009 at 5:28 pm #

    Thanks for the code!

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

    • Riyad Kalla 25. Nov, 2009 at 9:22 am #

      Mark, you’d just have to edit the index.php or page.php templates to include comments on the home page.

  19. Vikas Gupta 09. Dec, 2009 at 7:35 am #

    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.

  20. kiezel 12. Jan, 2010 at 8:00 am #

    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..

  21. Lisy 19. Jan, 2010 at 7:14 pm #

    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?

  22. Riyad Kalla 19. Jan, 2010 at 7:18 pm #

    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!

  23. Tony 14. Mar, 2010 at 5:12 pm #

    Thanks alot for sharing this, it’s helped alot to have a commentbox on pages….

    Cheers.

  24. 2leep 14. Mar, 2010 at 7:29 pm #

    thankx for the article the comments did also helped me

  25. Anonymous 09. Apr, 2010 at 1:31 pm #

    OMG thank you!

  26. Anonymous 11. Apr, 2010 at 12:35 pm #

    Thanks! That worked for me!

  27. Anonymous 11. Apr, 2010 at 12:51 pm #

    Wonderfull Thanks!

  28. Anonymous 07. May, 2010 at 7:55 am #

    just wanted to say thanks for this – jumped into an existing site to redesign it and couldn’t figure it out. saved me a lot of time!

  29. Riyad Kalla 07. May, 2010 at 9:35 am #

    No prob Anon, glad it helped!

  30. Yunieski 17. Jun, 2010 at 6:49 am #

    I am wonering something related with this, i have created some other pages in my wordpress like, about us, help, …but i donñt want conments to appear in those pages. What could i do to solve that problem.
    Thanks.

    • Riyad Kalla 17. Jun, 2010 at 9:42 am #

      Yunieski,

      Good question — when you edit the main page template and added the comments to it, that means every single page that uses that actual PHP template will have comments — this includes all custom pages you create like About, Contact, etc.

      What you want to do is copy the page template to another template file, like page-nocomments.php and then on your About and Contact pages, in the dropdown on the right hand side where you select the “template” to use for the page, you select “page-nocomment” for that template — so that page will be rendered using that page template that doesn’t include the comment block.

      NOTE: WordPress uses a certain comment-format at the top of the page template files to determine the name that displays in the dropdown in the page-editing interface… so at the top of the template page you’ll see a name in a simple comment at the top, you’ll want to change it for the page-nocomment.php file so it doesn’t also show up in the template drop down as another “page” template and then you can’t tell them apart.

  31. adrian 05. Jul, 2010 at 1:31 pm #

    Can you tell me on wich php file have to put the code ?
    wp-content/themes/worn-wall/*. php?

    on template.php i can’t find )

    thank you

    http://www.banatuldemunte.ro

    • Riyad Kalla 05. Jul, 2010 at 4:36 pm #

      adrian, you put that code in any template that you want to start showing comments. So if you wanted to edit your page.php template for example that is used to display simple pages, then you would add it in there. If you wanted to edit the template that displays single posts, then that is single.php

      You’ll notice when you are making a post, over in the right hand side of WordPress in the “Template” dropdown you can actually select the PHP template file you want to render the page, that is how you can tell which template you’ll want to edit.

  32. Mike Carter 03. Sep, 2010 at 10:38 am #

    Wow! Did this help! Had NO idea how to enable comments in Pages. Great debt. Also, to Riyad Kalla for the “put anywhere” tip.

    • Riyad Kalla 03. Sep, 2010 at 10:45 am #

      Mike,

      Glad it helped!

      • Mike Carter 03. Sep, 2010 at 11:09 am #

        Riyad, would you do me a favor? Will take you about 3 min.

  33. Wolf Leonard 05. Sep, 2010 at 3:18 pm #

    Yours was a nice simple solution to a simple problem. Thanks Riyad ! ‘Wish it were all that cut and dry.

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