{"id":46627,"date":"2026-10-10T17:17:37","date_gmt":"2026-10-10T17:17:37","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46627"},"modified":"2026-10-11T05:18:18","modified_gmt":"2026-10-11T05:18:18","slug":"disable-comments-wordpress-without-plugin","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/disable-comments-wordpress-without-plugin\/","title":{"rendered":"Disable Comments in WordPress Completely Without a Plugin"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If a WordPress site has no blog, comments only attract spam. To disable comments in WordPress completely without a plugin, you have to switch them off in several places: post type support, the open\/closed check, existing comments, block theme templates and the admin screens. This snippet covers all of them in one code block.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\/**\n * Disable comments everywhere: front end, block themes, REST, XML-RPC and wp-admin.\n *\/\n\n\/\/ Remove comment and trackback support from every post type.\nadd_action( 'init', 'dpc_remove_comment_support', 100 );\nfunction dpc_remove_comment_support(): void {\n\tforeach ( get_post_types() as $post_type ) {\n\t\tif ( post_type_supports( $post_type, 'comments' ) ) {\n\t\t\tremove_post_type_support( $post_type, 'comments' );\n\t\t\tremove_post_type_support( $post_type, 'trackbacks' );\n\t\t}\n\t}\n}\n\n\/\/ Close comments and pings. Forms, wp-comments-post.php, REST and pingbacks all check these.\nadd_filter( 'comments_open', '__return_false', 20 );\nadd_filter( 'pings_open', '__return_false', 20 );\n\n\/\/ Hide existing comments and counts.\nadd_filter( 'comments_array', '__return_empty_array', 20 );\nadd_filter( 'get_comments_number', '__return_zero', 20 );\n\n\/\/ Block themes query comments directly, so empty the comment blocks.\nforeach ( array( 'core\/comments', 'core\/post-comments-form', 'core\/post-comments-count', 'core\/post-comments-link', 'core\/latest-comments' ) as $dpc_block ) {\n\tadd_filter( \"render_block_{$dpc_block}\", '__return_empty_string' );\n}\nunset( $dpc_block );\n\n\/\/ No comments feed link, no Recent Comments widget.\nadd_filter( 'feed_links_show_comments_feed', '__return_false' );\nadd_action( 'widgets_init', 'dpc_unregister_comments_widget' );\nfunction dpc_unregister_comments_widget(): void {\n\tunregister_widget( 'WP_Widget_Recent_Comments' );\n}\n\n\/\/ wp-admin: menu, screens and admin bar.\nadd_action( 'admin_menu', 'dpc_remove_comments_menu' );\nfunction dpc_remove_comments_menu(): void {\n\tremove_menu_page( 'edit-comments.php' );\n}\n\nadd_action( 'load-edit-comments.php', 'dpc_redirect_comments_screen' );\nadd_action( 'load-comment.php', 'dpc_redirect_comments_screen' );\nfunction dpc_redirect_comments_screen(): void {\n\twp_safe_redirect( admin_url() );\n\texit;\n}\n\nadd_action( 'admin_bar_menu', 'dpc_remove_comments_admin_bar', 999 );\nfunction dpc_remove_comments_admin_bar( WP_Admin_Bar $admin_bar ): void {\n\t$admin_bar-&gt;remove_node( 'comments' );\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Post types<\/strong>: on <code>init<\/code> at priority 100, after themes and plugins have registered their post types, comment and trackback support is removed, so the Discussion panel disappears from the editor.<\/li>\n\n\n<li><strong>Open or closed<\/strong>: <code>comments_open<\/code> and <code>pings_open<\/code> return <code>false<\/code>. WordPress checks these before it shows a form, before it accepts a comment through wp-comments-post.php or the REST API, and before it accepts a pingback.<\/li>\n\n\n<li><strong>Existing comments<\/strong>: <code>comments_array<\/code> is emptied for classic themes, and <code>get_comments_number<\/code> returns 0, so &#8220;3 Comments&#8221; links and counts disappear.<\/li>\n\n\n<li><strong>Block themes<\/strong>: the Comments, Comments Form, Comments Count, Comments Link and Latest Comments blocks render as empty strings, because block themes query comments directly instead of going through <code>comments_array<\/code>.<\/li>\n\n\n<li><strong>wp-admin<\/strong>: the Comments menu is removed, direct visits to <code>edit-comments.php<\/code> and <code>comment.php<\/code> redirect to the Dashboard, and the admin bar bubble, the Recent Comments widget and the comments feed link are gone.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Compared with the older One-Click Import version: support is removed on <code>init<\/code> instead of <code>admin_init<\/code>, so it also applies on the front end; the redirect uses <code>load-{page}<\/code> hooks and <code>wp_safe_redirect()<\/code>; block themes are covered; every function has the <code>dpc_<\/code> prefix; and the removal of <code>dashboard_recent_comments<\/code>, a widget WordPress no longer has, is dropped.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> go to <strong>Code Blocks \u2192 Add New<\/strong> and give the block a name. Set <strong>Trigger location<\/strong> to <strong>Everywhere<\/strong>, tick <strong>PHP<\/strong> under <strong>Script location<\/strong>, paste the code into the PHP editor and publish. Leave <strong>Action\/Hook<\/strong> empty. Everywhere matters here: the code must run in wp-admin for the menus, on the front end for the templates, and in REST and wp-comments-post.php requests, which neither <strong>Admin only<\/strong> nor <strong>Conditions<\/strong> code reaches.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same code also works unchanged in a small plugin or an mu-plugin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep WooCommerce reviews (they are comments of type <code>review<\/code>): in <code>dpc_remove_comment_support()<\/code> skip <code>'product'<\/code>, and replace the two <code>__return_false<\/code> filters with a function that returns <code>false<\/code> unless <code>get_post_type( $post_id )<\/code> is <code>'product'<\/code>.<\/li>\n\n\n<li>Delete old comments for good: empty them in <strong>Comments<\/strong> before you enable the snippet, or run <code>wp comment delete $(wp comment list --format=ids) --force<\/code> with WP-CLI.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Comments are hidden, not deleted. Disable the code block and they come back.<\/li>\n\n\n<li>The <strong>Activity<\/strong> box on the Dashboard can still list comments that already exist.<\/li>\n\n\n<li>WooCommerce product reviews are comments too, so they are closed and hidden unless you apply the customisation above.<\/li>\n\n\n<li>Don&#8217;t expect a measurable speed gain; the benefit is no spam and a cleaner admin.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Disable comments in WordPress completely without a plugin: close forms, hide old comments, empty comment blocks and remove the admin screens.<\/p>\n","protected":false},"author":1,"featured_media":46908,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Disable Comments in WordPress Completely Without a Plugin","description":"Disable comments in WordPress completely without a plugin: close forms, hide old comments, empty comment blocks and remove the admin screens."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[3],"tags":[140,173,166,174,6],"dpc_library":[204],"class_list":["post-46627","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-block-themes","tag-comments","tag-scripts-organizer","tag-spam","tag-wp-admin"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46627"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46627\/revisions"}],"predecessor-version":[{"id":46666,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46627\/revisions\/46666"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46908"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46627"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46627"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}