Get rid of comments on WordPress “pages”

I have a “Contact Us” page on AggieCampusology.com and a “Share a Story” page, and in the default WordPress setups, Pages include the ability to post comments, just like a regular Post does. But that doesn’t make any sense on a “Contact Us” or “Share a Story” page, where users are already being presented forms to be filled out, and I was worried about users getting confused, so, I wanted to remove the comments section from those pages completely, if I could.

The solution is:

1. Create a custom page template.
2. Remove the “comments” code from that template.
3. Use the new Custom template for the pages you don’t want comments on.

Hopefully the following is a decent enough explanation, if you want to do the same yourself:

  1. Copy the “page.php” file in your theme directory.
  2. Call the new copy of “page.php” “custompage.php” or something similar.
  3. Open “custompage.php” in your text editor, and replace it’s contents with this:

    <?php
    /**
    Template Name: CustomPage

    Page template, without comments at the bottom.
    */

    get_header(); ?>

    <div id="container">
    <div id="content" role="main">

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if ( is_front_page() ) { ?>
    <h2 class="entry-title"><?php the_title(); ?></h2>
    <?php } else { ?>
    <h1 class="entry-title"><?php the_title(); ?></h1>
    <?php } ?>

    <div class="entry-content">
    <?php the_content(); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
    </div><!-- .entry-content -->
    </div><!-- #post-## -->

    <?php endwhile; // end of the loop. ?>

    </div><!-- #content -->
    </div><!-- #container -->

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    *Note: all the above really does is duplicate the template called “loop-page.php” removing this code:
    <?php comments_template( '', true ); ?>
    **Note: you can also just download the above code from here, if you’d like to see it a little more cleanly.

  4. Save the “custompage.php” file.
  5. Open the page you want the comments removed from in the WordPress Admin UI.
  6. On the right under “Page Attributes” change the template from “Default Template” to “CustomPage”:
    Wordpress Page Attributes Admin UI - Select CustomPage
  7. Click “Update” to save the new settings.
  8. Check your new pages in a browser, to make sure everything works the way you want it (specifically that there are no longer “comments” at the bottom of your commentless pages!

If you want to read up more on creating your own page templates for WordPress, check the codex.

Oh, and sidebar here: I’m using TDO Mini Forms to power the “Share a Story” page on AggieCampusology.com, because I wanted a quick and easy way for users to submit entries, that will work with the publishing workflow that’s naturally included with WordPress, without making a user “register” or anything… seems to be working so far…

3 Responses to “Get rid of comments on WordPress “pages””


  • There’s a much easier way.
    On any individual WordPress page, when you edit it there is a Discussion section. Uncheck the box allow comments and Save.

    Done.

    • Jason, I appreciate the guidance, but in WordPress 3.0, there actually isn’t a “discussion” section on the page, or even on the post, UI page. You technically have to “edit” pages using the “bulk actions” buttons, on the “Posts” or “Pages” page… and then you can turn off comments… there’s no easy way to do it when you’re creating a page… and this is the way to do it across the board, without having to muck with things over the longer term…

  • Can you go to the page you want to disable comments on, click ‘Screen Options’ (top right), then check Discussion, and when the discussion module appears uncheck Allow Comments and Allow Trackbacks and Pingbacks on this page?

Leave a Reply