Hello WordPress Developer,
Today, i we will show you how to disable comments in wordpress. This article will give you simple example of how to disable comments in wordpress. you will learn how to disable comments in wordpress.
So let’s follow few step to create example of how to disable comments in wordpress. just paste this below code in your theme functions.php.
Example 1
Disable comments on the front end
add_filter('comments_open', '__return_false', 20, 2); add_filter('pings_open', '__return_false', 20, 2);
Example 2
hide existing comments then paste this below code
add_filter('comments_array', '__return_empty_array', 10, 2);
Example 3
Remove comments links from admin bar
add_action('admin_menu', function () { remove_menu_page('edit-comments.php'); }); add_action('init', function () { if (is_admin_bar_showing()) { remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60); } });