Last active
October 10, 2024 14:30
-
-
Save valentin-grenier/27432c07bd76daef2eb3c95a053eb4d8 to your computer and use it in GitHub Desktop.
Completely disable WordPress comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Code authored by Valentin Grenier - Studio Val | |
* Freelance WordPress Developer from Toulouse, France | |
* https://studio-val.fr | |
* | |
* Completely disable WordPress comments | |
* 1. Removes from admin menu | |
* 2. Removes from post and pages | |
* 3. Removes from admin bar | |
* 4. Prevents comments from being stored in the database | |
*/ | |
function my_theme_remove_comments() { | |
remove_menu_page('edit-comments.php'); | |
} | |
add_action('admin_menu', 'my_theme_remove_comments'); | |
function my_theme_remove_comment_support() { | |
remove_post_type_support('post', 'comments'); | |
remove_post_type_support('page', 'comments'); | |
} | |
add_action('init', 'my_theme_remove_comment_support', 100); | |
function my_theme_admin_bar_render() { | |
global $wp_admin_bar; | |
$wp_admin_bar->remove_menu('comments'); | |
} | |
add_action('wp_before_admin_bar_render', 'my_theme_admin_bar_render'); | |
// Prevent comments from being stored in the database | |
function my_theme_disable_comments($open, $post_id) { | |
return false; // Disable comments for all posts | |
} | |
add_filter('comments_open', 'my_theme_disable_comments', 10, 2); | |
add_filter('pings_open', 'my_theme_disable_comments', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment