Disable WordPress Comments

Published by Vijay Kumar

There are a few different ways you can disable comments in WordPress using either the .htaccess file or the wp-config.php file.

To disable comments using the .htaccess file, you can add the following code to your .htaccess file:

# disable comments
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteCond %{QUERY_STRING} !^action=edit [NC]
RewriteCond %{QUERY_STRING} !^action=replytocom [NC]
RewriteRule ^(.*)$ /index.php [L,R=301]

This will disable comments on all posts and pages on your WordPress site.
To disable comments using the wp-config.php file, you can add the following code to your wp-config.php file:

// disable comments
function df_disable_comments_status() {
return false;
add_filter('comments_open', 'df_disable_comments_status', 20, 2);
add_filter('pings_open', 'df_disable_comments_status', 20, 2);

// hide existing comments
function df_disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);

// remove comments page in menu
function df_disable_comments_admin_menu() {
add_action('admin_menu', 'df_disable_comments_admin_menu');

// remove comments links from admin bar
function df_disable_comments_admin_bar() {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
add_action('init', 'df_disable_comments_admin_bar');

This will disable comments on all posts and pages, hide any existing comments, remove the comments page from the WordPress admin menu, and remove the comments links from the WordPress admin bar.

It's important to note that these changes will not delete any comments that have already been made on your site. If you want to delete existing comments, you'll need to do that manually from the WordPress dashboard.

Share the article: 

Get Started on Your Digital Success Journey Today!

Let's Talk
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram