So, everyone knows that you can easily turn on and off comments on WordPress pages and posts. Unfortunately for most (depending on theme) when you do this, it leaves a little unsightly blank area or “Comments are Closed” text behind using the default “built-in” method.
This gets annoying as it leaves behind traces of itself and doesn’t look very professional.
Example 1: Leftover junk from using the built-in “comments off” feature:
What we’re going to do now is conditionally ALLOW comments to exist only on certain PAGES (not posts) by ID number. This way, not only is the comment table gone, but any traces it usually leaves of itself will also disappear due to this method. Where you find the code may depend on your theme. I am using the TwentyTen theme for this example.
In the TwentyTen theme, the PHP code snippet is located in the following location:
Depending on theme, you may need to just open: /wp-content/themes/themename/page.php
Either way, you’re looking for this line of code:
This is the page that calls to the “comments-template” which is the entire structure of the comments table and all of it’s contents.
Now, once you have located this snippet, the rest is very easy. Lets say that you want to ALLOW comments on only a few PAGES and have them completely stripped from others. Here’s how:Replace snippet with this line of code:
Utilizing the PHP “if” statement and “is_page” (WordPress) and then adding the array of pages allowed you can make good use of this tutorial. Just replace the “ID#” with the page ID that you would like to ALLOW comments on. You can easily locate your page ID# by hovering over the link. You can even use perma-link structure in lieu of ID#’s. For example replace ID# with “my-home-page” or whatever title your page shows in the URL bar of your browser.
Example 2: How it looks after code has been applied:
See… no more unsightly blank area where the comments should be.
Hope this tutorial helps you in further customizing your WordPress themes. Please let me know if you have any questions or if this worked for you.