AI Verified

Name

Complete hide Comments

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

Stranger-Vault

Scroll down to see more snippets from this codevault.

Wordpress Compatability

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

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:

14/11/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

Complete hide Comments

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

0

Related Snippets

Please see some snippets below related to this snippet..

General

Unverified

0

Body Class "scroll" on scroll

Added: 8 months ago

Last Updated: 6 months ago

General

AI Verified

0

Format date

Added: 9 months ago

Last Updated: 9 months ago

General

AI Verified

0

ACF_Fields_into_WordPress

Added: 2 months ago

Last Updated: 2 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

0

Complete hide Comments

Added: 10 months ago

Last Updated: 10 months ago