AI Verified

Name

Disable Comments

About

deactivates all Comment functions on WordPress Site<br/>Source: https://help.codesnippets.pro/article/52-disable-comments-in-wordpress-by-roy-eyal

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

BuffetITServices

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:

28/07/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 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_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} );
40 
41// Remove comments link in top admin bar
42add_action('admin_head', 'nocomments_css');
43function nocomments_css() {
44 echo '<style>
45 #wpadminbar ul#wp-admin-bar-root-default>li#wp-admin-bar-comments {
46 display:none;
47 }
48 </style>';
49}

0

Comments

  • FT

    1 year ago

    You could add 
    
    add_action('admin_head', 'nocomments_css');
    
    function nocomments_css() {
      echo '<style>
        #wpadminbar ul#wp-admin-bar-root-default>li#wp-admin-bar-comments {
          display:none;
        }
      </style>';
    }
    
    
    To remove the icon from admin top bar

Related Snippets

Please see some snippets below related to this snippet..

Security

AI Verified

1

Users: Create & Delete n New Users in WP Admin [SnipSnip.pro]

Added: 9 months ago

Last Updated: 6 months ago

Users: Create &amp; Delete n New Users in WP Admin [SnipSnip.pro] - <a href="https://snipsnip.pro/s/799" target="_blank" rel="nofollow noopener">https://snipsnip.pro/s/799</a> - This creates then dele...

Security

AI Verified

1

Force Login Shortcode

Added: 2 months ago

Last Updated: 2 months ago

Security

AI Verified

0

iFrame Destroyer

Added: 11 months ago

Last Updated: 11 months ago

This stops other sites from being able to show your site in an iFrame

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

1

disable Font Awesome

Added: 1 year ago

Last Updated: 1 year ago

Security

AI Verified

0

Disable Comments

Added: 1 year ago

Last Updated: 11 months ago

deactivates all Comment functions on WordPress Site<br/>Source: https://help.codesnippets.pro/article/52-disable-comments-in-wordpress-by-roy-eyal

Performance

AI Verified

0

disable Eicons

Added: 1 year ago

Last Updated: 1 year ago