AI Verified

Name

Disable Comments

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

ActionSkills

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.

Website/ Profile URL:

https://actionskills.co

History

Last modified:

06/02/2024

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

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

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

1

Remove CTP name from URL slug

Added: 1 year ago

Last Updated: 1 year ago

Code removes the Custom Post Type (CPT) name from the URL slug.

General

AI Verified

0

Stop Lazy Load

Added: 7 months ago

Last Updated: 7 months ago

General

AI Verified

0

Divi - Remove Gutenberg Block Library CSS from loading on the frontend

Added: 6 months ago

Last Updated: 5 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

0

Disable Comments

Added: 6 months ago

Last Updated: 5 months ago

General

AI Verified

0

Remove tag and category taxonomy

Added: 6 months ago

Last Updated: 6 months ago

Divi Builder

AI Verified

0

Divi - Disable Project CPT and Taxonomy

Added: 6 months ago

Last Updated: 6 months ago