Disable Comments
Most client sites don’t use WordPress comments at all, but there’s no single “turn comments off” switch — you need to drop comment support from post types, hide the admin UI (menu, dashboard widget, admin bar, the comments screen itself), and strip out any comments that already exist. This snippet bundles all of that into one class.
Our Blocksy child theme is configured to automatically include all PHP files from the inc/ directory, so this only takes one file.
-
Add the PHP Code
Section titled “Add the PHP Code”Create a new file named
DisableComments.phpinside theinc/folder of your Blocksy child theme and add the following code.<?phpnamespace Best4u\BlocksyChild\Classes;if (!defined('ABSPATH')) {exit;}/*** Class DisableComments** Removes all comment-related functionality from the WordPress admin.*/class DisableComments{public function __construct(){add_action('init', [$this, 'remove_comment_support']);add_action('admin_menu', [$this, 'remove_comments_admin_menu']);add_action('wp_dashboard_setup', [$this, 'remove_dashboard_metabox']);add_action('admin_bar_menu', [$this, 'remove_admin_bar_link'], 100);add_action('admin_init', [$this, 'redirect_comments_page']);add_filter('comments_array', [$this, 'hide_existing_comments'], 10, 2);}/*** Removes comment and trackback support from all post types.** @return void*/public function remove_comment_support(): void{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');}}}/*** Removes the "Comments" menu from the admin sidebar.** @return void*/public function remove_comments_admin_menu(): void{remove_menu_page('edit-comments.php');}/*** Removes the recent comments metabox from the dashboard.** @return void*/public function remove_dashboard_metabox(): void{remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');}/*** Removes the comments node from the admin bar.** @param \WP_Admin_Bar $wp_admin_bar* @return void*/public function remove_admin_bar_link($wp_admin_bar): void{$wp_admin_bar->remove_node('comments');}/*** Redirects users away from the comments management page.** @return void*/public function redirect_comments_page(): void{global $pagenow;if ($pagenow === 'edit-comments.php') {wp_redirect(admin_url());exit();}}/*** Filters out all existing comments from display.** @param array $comments* @return array*/public function hide_existing_comments($comments): array{return [];}}new DisableComments();Once you save this file, comments are disabled everywhere: post types stop declaring comment support, the admin menu/dashboard/admin bar entries disappear,
/wp-admin/edit-comments.phpredirects back to the dashboard, andcomments_arrayis filtered to always return an empty array so nothing renders on the front end either.
Customization
Section titled “Customization”To keep comments working for a specific post type, exclude it in remove_comment_support():
public function remove_comment_support(): void{ foreach (get_post_types() as $post_type) { if ($post_type === 'post') { continue; }
if (post_type_supports($post_type, 'comments')) { remove_post_type_support($post_type, 'comments'); remove_post_type_support($post_type, 'trackbacks'); } }}If you only want to hide the admin UI but keep accepting comments programmatically (e.g. a headless integration), drop the hide_existing_comments filter and leave the rest as-is.