How to Disable Comments in WordPress

Written by Jean Galea
Written by Jean Galea

Last updated on 17 Mar 2022

All the options currently available for turning off commenting on WordPress pages, posts or custom post types. Check out the various alternatives and choose the one you like best.

WP Mayor is supported by its audience. If you purchase through a link on our site, we may earn a commission. Here’s why you can trust us.

Table Of Contents

Table of Contents

Before We Get Started

Do you already have your website set up with a reliable host?

If not, or if you’re looking for a better option (free migration included) we’ve worked with our close friends at WP Engine to get our hands on an incredible hosting offer that’s ideal for WordPress sites.

It includes performance optimizations for your site, security features, automated updates, 1-click backups, and a bunch of free tools.

Get it here and save over $100 in your first year!

Introduction

Do you find the fact that WordPress sets the commenting functionality on for all posts, pages, and custom post types by default annoying?

Now we have a solution to that, just add the following to your functions.php file, paying attention to the switch conditions. Here we are disabling commenting on all new pages and ‘truck’ custom post types. Edit those as you require.

[php]
function my_default_content( $post_content, $post ) {
if( $post->post_type )
switch( $post->post_type ) {
case ‘page’:
case ‘truck’:
$post->comment_status = ‘closed’;
break;
}
return $post_content;
}
add_filter( ‘default_content’, ‘my_default_content’, 10, 2 );
[/php]

Note that this will only disable commenting for new pages and posts and not on those you have already created. For those, you will have to manually change the comment settings from the Edit Post/Page interface.

As an alternative to editing your functions.php, you can go for this plugin which disables commenting by default on Pages: Page Comments Off Please.

Yet another simple alternative is to remove or comment out the code in your page template (page.php) relating to the comment form. In the default TwentyTen theme this looks something like:

[php]
<?php comments_template( ”, true ); ?>
[/php]

<span style="font-weight: 400">Written by: </span>Jean Galea
Written by: Jean Galea

Jean Galea is an investor, entrepreneur, and blogger.

He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast.

His personal blog can be found at jeangalea.com.

WP Engine

Quick Links

Did you find this article helpful?

Share Your Discovery

Thank you to our partners for their support

Leave a Reply

Your email address will not be published. Required fields are marked *

 Discover more tips and tools. 
Join 5000+ designers, developers, and website builders that come to WP Mayor to find the best guides, tools, and services for their next website. One email every week.
WP Mayor Newsletter

What's missing?