How to Disable Comments in WordPress

Written by Jean Galea
Written by Jean Galea
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.

Partner Sponsors


Full disclosure: If you purchase through a link on our site, we may earn a commission. Learn more.

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.

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

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 comments_template( ”, true ); ?>

This article was filed in our archives.
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 podcast. His personal blog can be found at

In this article

Discover More

Share Your Thoughts

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

New discoveries, every week.
Join thousands of designers, developers, and builders that come to WP Mayor to find the best guides, tools, and services for their next website. One email, once a week.
WP Mayor Newsletter

Claim Your Free Website Tip 👇

Leave your name, email and website URL below to receive one actionable improvement tip tailored just for your website within the next 24 hours.

"They identified areas for improvement that we had not previously considered." - Elliot

By providing your information, you'll also be subscribing to our weekly newsletter packed with exclusive content and insights. You can unsubscribe at any time with just one click.

What's missing?