WordPress Fix: Allow Comments on Pages

WordPress Plugin

By default WordPress has the functionality in place for comments to be added to posts. However, out of the box there seems to be no ability to add comments to Pages created in WordPress – despite the fact that one of the settings when editing a Page is "Allow Comments".

The problem is not so much with WordPress itself as with the "Theme" or template you are using. A quick fix to one of the pages in the default theme will get you up and running.

How it is done

You will need to be able to edit the files in the default theme – either via the WordPress Admin (files must be writeable), or via FTP.

Open up the file called "page.php" which sits in the "wp-content/themes/default/" directory. Then replace it's contents with the following code and save/upload the file:

<?php get_header(); ?>
    <div id="content" class="narrowcolumn">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
            <h2><?php the_title(); ?></h2>
            <div class="entrytext">
                <?php 
                    the_content
('<p class="serif">Read the rest of this page </p>');
                    
link_pages('<p><strong>Pages:</strong> ''</p>''number'); 
                
?>
            </div>
        </div>
    <?php 
        
endwhile; endif;

        //Allow Admins to edit this page 
        
edit_post_link('Edit this entry.''<p>''</p>');

        //Fix to allow comments to be added to Pages
        
comments_template(); 
    
?>
    </div>
<?php 
    get_sidebar
();
    
get_footer();
?>


Of course, this example presumes you are working with the "default" theme. If you would like to fix another theme then the actual code that fixes everything is this single line:

<?php comments_template(); ?>


I hope this helps somebody – I know it would have saved me a few minutes…

Be Sociable, Share!