Completely Disable Comments

add_action(‘admin_init’, function () {n // Redirect any user trying to access comments pagen global $pagenow;n n if ($pagenow === ‘edit-comments.php’) {n wp_safe_redirect(admin_url());n exit;n }nn // Remove comments metabox from dashboardn remove_meta_box(‘dashboard_recent_comments’, ‘dashboard’, ‘normal’);nn // Disable support for comments and trackbacks in post typesn foreach (get_post_types() as $post_type) {n if (post_type_supports($post_type, ‘comments’)) {n remove_post_type_support($post_type, ‘comments’);n remove_post_type_support($post_type, ‘trackbacks’);n }n }n});nn// Close comments on the front-endnadd_filter(‘comments_open’, ‘__return_false’, 20, 2);nadd_filter(‘pings_open’, ‘__return_false’, 20, 2);nn// Hide existing commentsnadd_filter(‘comments_array’, ‘__return_empty_array’, 10, 2);nn// Remove comments page in menunadd_action(‘admin_menu’, function () {n remove_menu_page(‘edit-comments.php’);n});nn// Remove comments links from admin barnadd_action(‘init’, function () {n if (is_admin_bar_showing()) {n remove_action(‘admin_bar_menu’, ‘wp_admin_bar_comments_menu’, 60);n }n});


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *