Top

How to disable comment on a WordPress page or post

March 5, 2006 by  

This is a simple tip to help you exclude the comment template on certain pages or posts in your blog. Certain themes will have the comment template unavailable by default on their pages such as those with the single.php. Some other themes will require a small change to their index.php or single.php to disable this comment section.

Here it goes:

Disable comment on certain post.

 

  1. Login to you WordPress administration panel, then go to Presentation > Theme Editor.
  2. Open index.php or single.php and look for the line <?php comments_template(); ?>
  3. Change it to

     

    <?php if (!is_single("personal-details")) {comments_template();} ?>

     

    This instruction disables the comment template on a post slug entitled “personal-details” without the quotation mark.

  4. Press “Update File” and presto! The comment section on that page is disabled.

 

Disable comment on certain pages.

  1. If you have index.php page only and you want to exclude comments on certain pages. Repeat steps 1 and 2 above.
  2. But now change <?php comments_template(); ?> to

    <?php if (!is_page("contact") and !is_page("partners") and !is_page("Add link") ) {comments_template();} ?>

    This instruction prevents the comment template to be displayed on the “contact”, “partners” and “Add link” page. Check those pages on Sabahan.com and compare them with the “About” page. You’ll notice that the comments section is not available on that three pages.

  3. Update your index.php file to complete the process.

I am not a PHP programmer but this is easy enough to implement and it works for Sabahan.com and my other blogs using WordPress version 1.5 and 2.0.1 . If you know a better way of doing this, please leave your comment and share it with us. Cheers!

 

Update: As suggested my LcF below, another way of doing this is my placing the following code in your index.php page so that your comment template appears only when comment is enabled.

 

<?php if ('open' == $post-> comment_status) {
comments_template();
}
?>

Did you enjoy this post? Please subscribe via RSS or email.

Related posts

Comments

RSS feed | Trackback URI

9 Comments »

Comment by ZEO
2006-03-05 16:23:51

Dude, why don’t u just edit the page and untick ‘Allow Comments’ and ‘Allow Pings’ under Discussion block?

 
Comment by LcF
2006-03-05 16:54:53

An easier way is to check comment is enable or not for the post/page, then show comment template if comment is enable.

Sample code:
if (‘open’ == $post-> comment_status) {
comments_template();
}

 
Comment by Gaman
2006-03-05 17:01:33

Hi ZEO,

Yes you can do that but you will get the “No Comments” and “No comments yet” message at the bottom of your page.

If you don’t mind that, by all means you can simply untick the ‘Allow Comments’ checkbox.

For my purpose though, I made several changes to my comment template so even if the comment is unticked, the changes will still be visible.

LcF, nice tip.

 
Comment by mael Subscribed to comments via email
2008-02-22 12:39:45

Hi guys,

I’ve tried this and it’s work.

Firstly, login to your admin site. click the Presentation tab. In the Theme Edetor tab, search for index.php file.

Look for the below paragraph

Before

Tags: Tags: to disable the comment function.

 
Comment by Cassie
2008-05-07 08:37:24

I just edited page.php and replaced

with

comment_status) {
comments_template();
}
?>

Worked like a charm, thank you!

 
Comment by Simon Liew
2009-09-20 12:32:44

Thanks for sharing this useful information. Its working fine in my blog.

 
Comment by Shahid Subscribed to comments via email
2011-07-08 05:00:34

To hide the comments at specific page please change

to

in page.php

:(

 
Comment by ahmed Subscribed to comments via email
2011-11-03 00:37:12

it didnt work with me
i use minimatica theme
so i dont have
presentation tab
but i accessed index file
but i dont have

i have

get_header(); ?>

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post

Bottom