SNIPPET · FREE

WordPress

Disable WordPress comments completely

Remove comments and pings from the frontend and dashboard without deleting comments already stored.

What it does

Closes comments and pings, removes comment support from post types, blocks new submissions, hides existing comments and removes the main comment UI from wp-admin and the REST API.

Important. It does not delete comments already stored in the database.

How to use it

  1. Install the free Code Snippets plugin.
  2. Create a new PHP snippet.
  3. Paste the code and run it everywhere.
PHP · WordPress · Code Snippets
/**
 * Disable WordPress comments everywhere.
 *
 * Existing comments are not deleted; they are hidden from the frontend
 * and the comment UI is removed from wp-admin.
 */

add_action( 'init', function () {
    foreach ( get_post_types() as $post_type ) {
        remove_post_type_support( $post_type, 'comments' );
        remove_post_type_support( $post_type, 'trackbacks' );
    }
}, 100 );

add_filter( 'comments_open', '__return_false', 20 );
add_filter( 'pings_open', '__return_false', 20 );

add_filter( 'comments_array', function () {
    return array();
}, 10, 2 );

add_filter( 'get_comments_number', function () {
    return 0;
}, 20, 2 );

add_filter( 'preprocess_comment', function ( $commentdata ) {
    wp_die(
        esc_html__( 'Comments are disabled on this website.', 'mrc-snippets' ),
        '',
        array( 'response' => 403 )
    );
}, 0 );

add_action( 'admin_menu', function () {
    remove_menu_page( 'edit-comments.php' );
    remove_submenu_page( 'options-general.php', 'options-discussion.php' );
} );

add_action( 'admin_init', function () {
    global $pagenow;

    if ( in_array( $pagenow, array( 'edit-comments.php', 'options-discussion.php' ), true ) ) {
        wp_safe_redirect( admin_url() );
        exit;
    }

    remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
} );

add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
    $wp_admin_bar->remove_node( 'comments' );
}, 999 );

add_filter( 'rest_endpoints', function ( $endpoints ) {
    foreach ( $endpoints as $route => $handlers ) {
        if ( strpos( $route, '/wp/v2/comments' ) === 0 ) {
            unset( $endpoints[ $route ] );
        }
    }

    return $endpoints;
} );

How to use it

  1. Install Code Snippets Free in WordPress.
  2. Create a new PHP snippet.
  3. Copy and paste the code.
  4. Activate it in the required scope.

This is a simple option, not a requirement: experienced users can put the code in their own plugin or the appropriate location. Configure form IDs and any required providers before enabling Gravity Forms examples.