AI Verified

Name

Disable WordPress Comments

About

Remove Comments from Posts and Pages.

Language

PHP

Rating

Voted: 2 by 2 user(s)

Codevault

WebSquadron

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:

12/04/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 WordPress Comments

 
                    
1/*
2Comments in WordPress are like an open mic.
3Sometimes you want to turn the mic off.
4Silencing the comment section might just be your ticket to serenity.*/
5 
6function codesnippets_disable_comments() {
7 // Remove comment support for posts
8 remove_post_type_support( 'post', 'comments' );
9 
10 // Remove comment support for pages
11 remove_post_type_support( 'page', 'comments' );
12 
13 // Remove comments from the admin menu
14 remove_menu_page( 'edit-comments.php' );
15 
16 // Redirect comment-related URLs to the homepage
17 add_action( 'template_redirect', 'codesnippets_disable_comments_redirect' );
18}
19 
20function codesnippets_disable_comments_redirect() {
21 global $wp_query;
22 if ( is_single() || is_page() || is_attachment() ) {
23 if ( have_comments() || comments_open() ) {
24 wp_redirect( home_url(), 301 );
25 exit;
26 }
27 }
28}
29 
30add_action( 'admin_init', 'codesnippets_disable_comments' );

2

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

Show Page Title in WordPress Menu

Added: 3 months ago

Last Updated: 3 months ago

Adding HTML directly into a WordPress menu to dynamically fetch and display the page title is not supported through the WordPress menu editor interface out of the box. However, you can achieve dynamic...

WordPress Admin

AI Verified

0

Hide "Screen Options" on the Admin Dashboard

Added: 1 year ago

Last Updated: 1 year ago

This snippet hides the "Screen Options" tab on the WordPress Admin Dashboard, except for yourself. This leaves you in sole control over what info panels appear on the Dashboard. With this snippet ac...

WordPress Admin

AI Verified

0

Remove Code Snippets TinyMCE button

Added: 1 year ago

Last Updated: 1 year ago

Removes the Code Snippets button from the TinyMCE visual editor.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.