Home / Admin / Fully Disable Comments & Trackbacks (The “Nuclear” Option)
Duplicate Snippet

Embed Snippet on Your Site

Fully Disable Comments & Trackbacks (The “Nuclear” Option)

* Fully Disable Comments & Trackbacks (The "Nuclear" Option)
* Optimized for performance and UI clarity.

Code Preview
php
<?php
/**
 * Fully Disable Comments & Trackbacks (The "Nuclear" Option)
 * Optimized for performance and UI clarity.
 */
add_action('admin_init', function () {
    global $pagenow;
    if ($pagenow === 'edit-comments.php') {
        wp_safe_redirect(admin_url());
        exit;
    }
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
    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');
        }
    }
});
// Front-end lockdowns
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);
// UI removal
add_action('admin_menu', fn() => remove_menu_page('edit-comments.php'));
add_action('wp_before_admin_bar_render', function() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('comments');
});
// NEW: Disable REST API comments endpoint for security/performance
add_filter('rest_endpoints', function ($endpoints) {
    if (isset($endpoints['/wp/v2/comments'])) {
        unset($endpoints['/wp/v2/comments']);
    }
    if (isset($endpoints['/wp/v2/comments/(?P<id>[\d]+)'])) {
        unset($endpoints['/wp/v2/comments/(?P<id>[\d]+)']);
    }
    return $endpoints;
});
// NEW: Remove X-Pingback Header
add_filter('wp_headers', function($headers) {
    unset($headers['X-Pingback']);
    return $headers;
});

Comments

Add a Comment