fbpx
9

How to disable comment on a WordPress page or post

Last modified on 10th March, 2006

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();
}
?>

Related Posts
No related posts for this content
Victor
 

An engineer by training, Victor has been working full-time online as an Internet marketer, a programmer and an app developer since 2001. He has been blogging at Sabahan.com since 2006 sharing his experience and teaching people how to make money online. Click here to join his private Facebook Group for bloggers.

  • ahmed says:

    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(); ?>

  • Shahid says:

    To hide the comments at specific page please change

    to

    in page.php

    🙁

  • Simon Liew says:

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

  • […] as the ever popular “resume” or “about me” pages, you may want to checkout this post on removing the comments section from the bottom of a post.  If you see any customization on my […]

  • Cassie says:

    I just edited page.php and replaced

    with

    comment_status) {
    comments_template();
    }
    ?>

    Worked like a charm, thank you!

  • mael says:

    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.

  • Gaman says:

    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.

  • LcF says:

    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();
    }

  • ZEO says:

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

  • >
    Scroll Up

    Sign Up Below... For Tips and Tools to Help You Build a Better Blog

    >> Sign Up Now and get access to:


    • chevron-circle-right
      The exact methods I use to make money
    • chevron-circle-right
      Resources to increase traffic to your blog
    • chevron-circle-right
      The latest updates from Sabahan.com

    We hate spam. Unsubscribe anytime.

    arrow-down
    Pin
    Share
    Tweet
    Share
    0 Shares