Utilities & Scripts
Disable WordPress Comments

Info

Disables WordPress comments everywhere and removes all related features from both the front end and admin, reducing spam and unnecessary endpoints. Good for sites that don’t use comments and want things cleaner and simpler.

Utilities & Scripts
April 29, 2026

Setup

00

Add Custom PHP

Place the PHP snippet in your theme’s functions.php file or add it using a code snippets plugin to enable the logic.

<?php

/** Disable comments + pings by default. */
add_action('init', function () {
	update_option('default_comment_status', 'closed');
	update_option('default_ping_status', 'closed');
	update_option('default_pingback_flag', '0');
});


/** Remove comment + trackback support. */
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');
	}
});


/** Remove comment feeds. */
add_action('init', function () {
	remove_action('wp_head', 'feed_links_extra', 3);
});
add_filter('feed_links_show_comments_feed', '__return_false');


/** Close comments + pings. */
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);


/** Hide existing comments. */
add_filter('comments_array', '__return_empty_array', 10, 2);


/** Remove comment reply script. */
add_action('wp_enqueue_scripts', function () {
	wp_dequeue_script('comment-reply');
});


/** Block comments pages in admin. */
add_action('admin_init', function () {
	global $pagenow;

	if ($pagenow === 'edit-comments.php' || $pagenow === 'options-discussion.php') {
		wp_safe_redirect(admin_url());
		exit;
	}
});


/** Remove dashboard + menus. */
add_action('admin_init', function () {
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
});

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


/** Remove admin bar icon. */
add_action('admin_bar_menu', function ($wp_admin_bar) {
	$wp_admin_bar->remove_node('comments');
}, 999);


/** Disable pingbacks (XML-RPC). */
add_filter('wp_headers', function ($headers) {
	unset($headers['X-Pingback']);
	return $headers;
});

add_filter('xmlrpc_methods', function ($methods) {
	unset($methods['pingback.ping']);
	return $methods;
});


/** Remove REST comment routes. */
add_filter('rest_endpoints', function ($endpoints) {
	foreach ($endpoints as $route => $data) {
		if (strpos($route, 'comments') !== false) {
			unset($endpoints[$route]);
		}
	}
	return $endpoints;
});
00

Publish and preview live

Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.