Some of the tech powering WP Mayor today:
Best Picks
Quick Links
Resources
For WordPress Businesses
WP Mayor is supported by our dedicated partners:
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.
How to Disable Comments in WordPress
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.
[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]
In this article
Discover More
WP Panel Review: Tailoring the WordPress Dashboard to Your Agency’s Needs
A detailed exploration of WP Panel, a robust tool designed to streamline and customize the WordPress dashboard for agencies, developers, and more.
Copy-Paste with a Twist: 4 Surprising Ways to Clone a Website
Need to clone a website? You might be migrating or wanting to duplicate a theme design. Either way, we’ve got the best solutions for you.
InstaWP Review: Create WordPress Sandbox Sites the Easy Way
InstaWP lets you create new WordPress sandbox sites just by clicking a button. You can use them to test plugins, build client sites, create real interactive demos, or anything else.