How to disable comments in WordPress
Table of Content
Here is an example of a simple WordPress plugin that will disable comments on all posts:
<?php
/*
Plugin Name: Disable Comments
Description: This plugin disables comments on all posts.
Version: 1.0
Author: Your Name
*/
function disable_comments() {
remove_post_type_support( 'post', 'comments' );
}
add_action( 'init', 'disable_comments', 100 );
You can use this plugin by saving the code in a new file with the extension .php and uploading it to the /wp-content/plugins/ directory on your WordPress site. Once you’ve done that, you can activate the plugin from the “Plugins” section of your WordPress dashboard.
It’s important to note that this plugin will disable comments globally for all posts, this may not be what you want, in case you want to disable comments for specific post types, you can check the post type before disabling the comments using the following code snippet.
function disable_comments() {
if ( 'post' === get_post_type() ) {
remove_post_type_support( 'post', 'comments' );
}
}
Also, keep in mind that disabling comments won’t delete the existing comments, you would need to use a plugin or a custom function to delete the comments.
Three fixes for your WordPress site, from people who build them
We are a WordPress.com Pro Partner and we rebuild a lot of sites that started as a template with a logo on it. Send us yours and we will tell you what is holding it back, in plain English, within a week. If the answer is "it is fine", we will say that too.
"*" indicates required fields
One working day to acknowledge, up to a week for the review. Your details stay with the Defyn team in Sydney.
