AI Verified

Name

Disable WP Comments

About

Disable WP Comments, the simple way

Language

PHP

Rating

Voted: 1 by 1 user(s)

How to Setup Snippet

Just install and enjoy

Codevault

hoofer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

12/09/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Disable WP Comments

 
                    
1add_action('wp_before_admin_bar_render', function() {
2 global $wp_admin_bar;
3 $wp_admin_bar->remove_menu('comments');
4});
5 
6add_action('admin_init', function () {
7 // Redirect any user trying to access comments page
8 global $pagenow;
9 
10 if ($pagenow === 'edit-comments.php') {
11 wp_redirect(admin_url());
12 exit;
13 }
14 
15 // Remove comments metabox from dashboard
16 remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
17 
18 // Disable support for comments and trackbacks in post types
19 foreach (get_post_types() as $post_type) {
20 if (post_type_supports($post_type, 'comments')) {
21 remove_post_type_support($post_type, 'comments');
22 remove_post_type_support($post_type, 'trackbacks');
23 }
24 }
25});
26 
27// Close comments on the front-end
28add_filter('comments_open', '__return_false', 20, 2);
29add_filter('pings_open', '__return_false', 20, 2);
30 
31// Hide existing comments
32add_filter('comments_array', '__return_empty_array', 10, 2);
33 
34// Remove comments page in menu
35add_action('admin_menu', function () {
36 remove_menu_page('edit-comments.php');
37});
38 
39// Remove comments links from admin bar
40add_action('init', function () {
41 if (is_admin_bar_showing()) {
42 remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
43 }
44});
45 
46// clean up admin menu
47add_action( 'admin_menu', function() {
48 remove_menu_page( 'edit-comments.php' );
49});

1

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

MX ยท Add All Post Types to Dashboard "At a Glance"

Added: 1 year ago

Last Updated: 1 year ago

Add all post_types found in the database to the "At a Glance" dashboard widget

WordPress Admin

AI Verified

2

Completely Disable Comments

Added: 1 year ago

Last Updated: 3 months ago

This will disable comments on the entire site

WordPress Admin

AI Verified

2

Remove menus from dashboard for non Admin users

Added: 1 year ago

Last Updated: 11 months ago

This snippets allow you to hide dashboards menus for non-admin users.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

3

Autopopulate menu item with posts by post type

Added: 1 year ago

Last Updated: 11 months ago

Autopopulate menu item with posts by post type as submenu items

WordPress Admin

AI Verified

2

Disable admin notices by text string

Added: 1 year ago

Last Updated: 1 year ago

In $forbidden_message_strings array, provide a list of keywords or phrases that you want to disable. Provide a longer phrase to increase specificity

WordPress Admin

AI Verified

1

Save in WP Admin with CTRL + S

Added: 1 year ago

Last Updated: 1 month ago

Save time by hitting CTRL/CMD + S instead of scrolling to find the Save/Update/Publish button