Skip to Content
21 January, 2023

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.

Insights

The latest from our knowledge base