Friday, June 26, 2009

Turn Off Comment Section in WordPress Pages

I'm setting up a WordPress install with the primary intent of using it mainly as a content management system (CMS). I'm tinkering because a family member has started up a business and is looking for a web site. I want to give them something robust enough to meet their needs, yet simply enough that they don't have to call me every time they want to update or add something.

WordPress is cake to install, so I had an instance running in less than 10 minutes. I edited the included About page that comes with the default install, turned off Allow Comments and Allow Pings, then viewed the page. At the bottom of the page it was still tacking on the comments section:

Ug. I poked around and couldn't figure out how to turn it off, so I resorted to a handy-dandy Internet search and found the solution.

In your theme, you will have a page named single.php, or index.php. Use the editor to view the source code for the page. In the code, the comments template is called with:
<?php comments_template(); // Get wp-comments.php template ?>

Comment that code out:

<!--<?php comments_template(); // Get wp-comments.php template ?>-->

and add this:

php if(is_page(array(27,32,56))){
//do nothing

Where the comma separated numbers correspond to the page_id.

The comment section will still show up on blog posts, but not on any of the pages you identify in the above code.

No comments: