AI Verified

Name

Disable comments in WordPress via the functions.php

About

Disable comments in WordPress via the functions.php

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

jernastyle

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.4

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:

22/12/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 in WordPress via the functions.php

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

0

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

פונקציה שמוסיפה את הפריפיקס tel: לערך השדה ב ACF

Added: 2 months ago

Last Updated: 2 months ago

יצירת קישור לטלפון בתוסף ACF בוורדפרס ולהוסיף באופן אוטומטי את הפריפיקס "tel:" למספר הטלפון

WordPress Admin

AI Verified

0

Hide WP Block Editor on specific post type

Added: 1 year ago

Last Updated: 1 year ago

WordPress Admin

AI Verified

0

Display snippet line numbers

Added: 1 year ago

Last Updated: 1 year ago

Based on work by platypus424 and germankiwi, this snippet will allow you to see code on a particular line number from all of your snippets, allowing you to track down exactly where an error might be o...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

0

Disable comments in WordPress via the functions.php

Added: 8 months ago

Last Updated: 8 months ago

Disable comments in WordPress via the functions.php

General

AI Verified

0

// Securely include the Prednosti Custom Post Type if it exists

Added: 9 months ago

Last Updated: 9 months ago