Disable WordPress Comment System Completely

Here’s a comprehensive function to completely disable the WordPress comment system:

<?php
// Completely disable WordPress comments and related functionality
function disable_comments_system() {
    // Disable support for comments and trackbacks in post types
    foreach (get_post_types() as $post_type) {
        if (post_type_supports($post_type, 'comments')) {
            remove_post_type_support($post_type, 'comments');
            remove_post_type_support($post_type, 'trackbacks');
        }
    }
    
    // Close comments on all existing posts
    update_option('close_comments_for_old_posts', 1);
    update_option('close_comments_days_old', 0);
    update_option('comment_registration', 1);
    update_option('default_ping_status', 'closed');
    update_option('default_comment_status', 'closed');
    
    // Redirect any comment feed requests to homepage
    add_action('template_redirect', function() {
        if (is_comment_feed()) {
            wp_redirect(home_url(), 301);
            exit;
        }
    });
    
    // Remove comments page from admin menu
    add_action('admin_menu', function() {
        remove_menu_page('edit-comments.php');
        remove_submenu_page('options-general.php', 'options-discussion.php');
    });
    
    // Remove comments links from admin bar
    add_action('wp_before_admin_bar_render', function() {
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu('comments');
    });
    
    // Remove dashboard comments widget
    add_action('wp_dashboard_setup', function() {
        remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
    });
    
    // Disable comments REST API endpoint
    add_filter('rest_endpoints', function($endpoints) {
        unset($endpoints['/wp/v2/comments']);
        unset($endpoints['/wp/v2/comments/(?P<id>[\d]+)']);
        return $endpoints;
    });
    
    // Remove comment form completely (front-end)
    add_filter('comments_open', '__return_false', 20, 2);
    add_filter('pings_open', '__return_false', 20, 2);
    add_filter('comments_array', '__return_empty_array', 10, 2);
    
    // Remove comment-reply script
    add_action('wp_enqueue_scripts', function() {
        wp_deregister_script('comment-reply');
    }, 100);
    
    // Remove comment form from templates
    add_action('init', function() {
        // Remove comment-reply script
        remove_action('wp_head', 'feed_links_extra', 3);
        
        // Remove comment form from wp_head
        remove_action('wp_head', 'feed_links', 2);
        
        // Remove comment form from content
        remove_filter('the_content', 'wpautop');
        add_filter('the_content', function($content) {
            if (is_singular()) {
                $content = preg_replace('/<div[^>]+id="respond"[^>]*>.*?<\/div>/is', '', $content);
                $content = preg_replace('/<h3[^>]+id="reply-title"[^>]*>.*?<\/h3>/is', '', $content);
                $content = preg_replace('/<form[^>]+id="commentform"[^>]*>.*?<\/form>/is', '', $content);
            }
            return $content;
        });
    });
}
add_action('init', 'disable_comments_system');

// Remove comment form from theme templates (additional safety)
add_filter('theme_page_templates', function($templates) {
    unset($templates['comments.php']);
    return $templates;
});

// Hide comments in admin for all post types
add_action('admin_init', function() {
    $post_types = get_post_types();
    foreach ($post_types as $post_type) {
        if (post_type_supports($post_type, 'comments')) {
            remove_post_type_support($post_type, 'comments');
            remove_post_type_support($post_type, 'trackbacks');
        }
    }
});
?>
  1. Add this code to your theme’s functions.php file or in a custom plugin
  2. The function will:
    • Remove comment support from all post types
    • Close comments on all existing posts
    • Disable comments and pingbacks by default
    • Remove comment-related admin menu items
    • Remove comment links from the admin bar
    • Remove the comments dashboard widget
    • Disable the comments REST API endpoints
    • Redirect comment feeds to the homepage

Additional Steps for Stubborn Comment Forms

If the comment form still appears after adding this code:

  1. Check your theme files: Some themes hard-code the comment form. Look in these files:
    • comments.php
    • single.php
    • page.php
    • content-single.php
    • Any files with comment_form() calls
  2. Add CSS to hide comments (as last resort)
add_action('wp_head', function() {
    echo '<style>
        #comments, #respond, .comments-area, .comment-respond, 
        .comment-form, .comments-title, .comment-list {
            display: none !important;
        }
    </style>';
});
  1. Check for any other plugins that might be adding comment functionality.

This enhanced solution should remove all traces of the comment system, including forms that appear when logged in as an admin.