WordPress: Switching Off Comments on Pages by Default

When setting up new WordPress sites, as I do frequently for client projects, I’m frequently irritated by the need to manually switch comments off for WordPress Pages. There are really very few instances when I will need them enabled.

Why is this a big deal? Mainly because I like to switch off, and hide, functions of the software which are unnecessary for my clients to lessen their confusion when navigating around the site admin. I also, of course, remove Comments in the page templates too but that leaves you (or the client actually) with that confusing checkbox when Quick Editing pages.

Anyway, to get back to the point… There are two things I wanted to mention that can be done.

1. Disable Comments for Pages in your Theme

This requires a simple snippet of code to be added to your functions.php file.

/**
* No Comments on Pages
*/
add_action('init', 'pages_nocomments');


function pages_nocomments() {
remove_post_type_support( 'page', 'comments' );
}

Simple as that! Now, you’re no longer bothered by the Comments. However, if you set up your Page structure before adding that to your theme, you will also need #2.

2. Disable Comments for Pages in your Database

This seems a bit scarier than just adding a little code to a file, but I’m keeping it simple here! Log in to phpMyAdmin, or whichever Database GUI is used by your host, and select your WordPress database. Then run the following code (in phpMyAdmin you click the SQL tab – other GUIs may vary)

update wp_posts set comment_status = 'closed' where post_type = 'page'

N.B. If you have changed the Table Prefix in your wp-config.php file, don’t forget to update the code above with the correct prefix for the Posts table.