/** * Disable support for comments and trackbacks in post types */ function itc_disable_comments_post_types_support() { $post_types = get_post_types(); foreach ($post_types as $post_type) { if (post_type_supports($post_type, 'comments')) { remove_post_type_support($post_type, 'comments'); remove_post_type_support($post_type, 'trackbacks'); } } } add_action('admin_init', 'itc_disable_comments_post_types_support'); /** * Close comments on the front-end (force comments_open() and pings_open() to return false) */ function itc_disable_comments_status() { return false; } add_filter('comments_open', 'itc_disable_comments_status', 20, 2); add_filter('pings_open', 'itc_disable_comments_status', 20, 2); /** * Hide existing comments (always return an empty array) */ function itc_disable_comments_hide_existing($comments) { return []; } add_filter('comments_array', 'itc_disable_comments_hide_existing', 10, 2); /** * Block comment‐related feeds (e.g., /comments/feed/) */ function itc_disable_comments_feed_redirect() { if (is_comment_feed()) { wp_redirect(home_url(), 301); exit; } } add_action('template_redirect', 'itc_disable_comments_feed_redirect'); /** * Disable XML‐RPC methods for pingbacks/trackbacks */ add_filter('xmlrpc_methods', function($methods) { if (isset($methods['pingback.ping'])) { unset($methods['pingback.ping']); } if (isset($methods['pingback.extensions.getPingbacks'])) { unset($methods['pingback.extensions.getPingbacks']); } return $methods; }); /** * Remove the comment-reply script from front-end */ function itc_disable_comment_reply_script() { wp_dequeue_script('comment-reply'); } add_action('wp_print_scripts', 'itc_disable_comment_reply_script'); /** * Remove any “Comments” links from custom Nav Menus */ function itc_remove_comments_from_nav_menus($items, $args) { foreach ($items as $key => $item) { // If the menu item’s URL contains “#comments” or “/comments/” or “/feed/comments/”, remove it if ( strpos($item->url, '#comments') !== false || strpos($item->url, '/comments/') !== false || strpos($item->url, '/feed/comments/') !== false ) { unset($items[$key]); } } return $items; } add_filter('wp_nav_menu_objects', 'itc_remove_comments_from_nav_menus', 10, 2);