WordPress.org

Ready to get started?Download WordPress

Forums

How to disable comments on pages (all at once) (11 posts)

  1. Jack
    Member
    Posted 5 years ago #

    I know there is this option to allow/disallow comments, but I want to allow comments on all posts and disallow comments on all pages.
    Is there a plugin that gives us two options to enable/disable comments?

    It's for a site a lot of people are going to add pages to, and I'm sure some will forget to turn comments off...

  2. Jack
    Member
    Posted 5 years ago #

    Since no one posted a reply so far...

    Pages are very often used as containers for static information, very different from a blog post. So wouldn't it be logical to have an option to disable comments for all pages and enable them for blog posts?

    Am I making sense? And could this be done by some plugin or other piece of code?

  3. llamaman
    Member
    Posted 5 years ago #

    The way that I accomplish this is to create a file called page.php and add it to my template directory. This page.php file is identical to my index.php file, except I stripped all the code related to comments.

    For more information on the Template Hierarchy: http://codex.wordpress.org/Template_Hierarchy

  4. llamaman
    Member
    Posted 5 years ago #

    Another way to accomplish this without using a page.php file is to insert the following code into your index.php file:

    <?php
    										/* If we are on a page, then hide comments */
    										if (is_page()) {
    											/* do nothing */
    										} else { 
    
    comments_popup_link('No Comments »', '1 Comment »', '% Comments »');										comments_template();
    										}
    									?>
  5. llamaman
    Member
    Posted 5 years ago #

    Whoa! The formatting got messed up on that last post. Here is a cleaned up version:

    <?php
    /* If we are on a page, then hide comments */
    if (is_page()) {
    /* do nothing */
    } else {
    comments_popup_link('No Comments »', '1 Comment »', '% Comments »');
    comments_template();
    }
    ?>
  6. Parmenti
    Member
    Posted 5 years ago #

    is there something else that needs to be done? I added the page.php file and it doesn't seem to be following that. It's still doing the same thing it always did. your help would be appreciated

  7. Parmenti
    Member
    Posted 5 years ago #

    also, the code the person mention doesn't seem to work either.

  8. llamaman
    Member
    Posted 5 years ago #

    You could remove the "comments_popup_link" code listed above from your "page.php". This, technically, wouldn't stop comments, but it would make them invisible to visitors.

  9. strange_attractor
    Member
    Posted 5 years ago #

    Parmenti, you need to add the following code at the top of your page.php file to make WordPress recognize it as a template. Then you can choose the template by name when you create or edit a page. If your template is named "Snarfer", then it would look like this:

    <?php
    /*
    Template Name: Snarfer
    */
    ?>

    This example is taken from a page I found useful, in the section on creating your own page templates: http://codex.wordpress.org/Pages#Page_Templates

  10. futureexpat
    Member
    Posted 5 years ago #

    I'm having the opposite problem. I want to allow comments on pages, and have checked such on the Discussion panel of the admin area. However, no comment button appears. Is this a template issue?

  11. florida-internet-marketing
    Member
    Posted 4 years ago #

    Thanks this helped me!

Topic Closed

This topic has been closed to new replies.

About this Topic