WordPress.org

Ready to get started?Download WordPress

Forums

Disable Comments on Pages (9 posts)

  1. Brain916
    Member
    Posted 7 years ago #

    A new template I am working with has comments on individual pages.
    I wanted to know, how do I disable this? Thank you.

  2. Class
    Member
    Posted 7 years ago #

    Edit 'single.php' (or whatever the name of your templatefile is), delete the comment tags.

  3. Brain916
    Member
    Posted 7 years ago #

    Thank you!

  4. moshu
    Member
    Posted 7 years ago #

    For Pages the default template is page.php (not single.php).

  5. Class
    Member
    Posted 7 years ago #

    Ops that's right, thanks for the correction, moshu.

  6. vintagepretty
    Member
    Posted 7 years ago #

    We've got a similar problem, which this doesn't seem to solve.

    Our aim is to keep comments on posts, but not have any commenting on pages (not even a "No Comments Sorry, the comment form is closed at this time." section at the bottom.)

    In the theme we're using, we've tried removing the "<?php comments_template(); // Get wp-comments.php template ?>" line in index.php but this hides comments from everything. Is there something we can put around this to say "if page is a post then show comments else don't?"

    (The theme does not have a seperate page.php)

  7. Chris_K
    Member
    Posted 7 years ago #

    The simplest approach would be to copy index.php to page.php and make it a proper Page Template (see [[Pages]).

    Or, if you're more or a coder type, have a look at Conditional_Tags.

  8. jamaal
    Member
    Posted 7 years ago #

    I have looked at the Conditional_Tags codex, but I cant see (maybe I'm just dumb) how to disable comments on pages but leave them on posts.

    Please please help!

    Jay

  9. Eetu
    Member
    Posted 6 years ago #

    Oh, old post and still open. Here's how to do it.

    1. Open your theme's index.php file.
    /wp-content/themes/YOURTHEME/index.php

    2. Find

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

    3. Replace with:

    <?php //let's show something else than comments on pages
    if (is_page()) {
    echo 'Some text';
    	} else {
    comments_template(); // Get wp-comments.php template
    }
    ?>

    4. You can replace 'Some text' with anything you want. If you want it to be blank, just use ''.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags