как отключить комментарии на wordpress полностью на сайте через хук

Чтобы полностью отключить комментарии на WordPress-сайте через хук (без редактирования темы напрямую и с возможностью отката), добавьте в файл functions.php вашей дочерней темы (или в плагин) следующий код:


// Отключить поддержку комментариев для всех записей и страниц
function 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', 'disable_comments_post_types_support');

// Закрыть комментарии при создании новых записей
function disable_comments_open($open, $post_id) {
    return false;
}
add_filter('comments_open', 'disable_comments_open', 10, 2);

// Скрыть метабокс комментариев в админке
function disable_comments_admin_menu() {
    remove_meta_box('commentstatusdiv', 'post', 'normal');
    remove_meta_box('commentstatusdiv', 'page', 'normal');
}
add_action('admin_menu', 'disable_comments_admin_menu');

// Удалить комментарии из админ-панели
function disable_comments_admin_bar() {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
}
add_action('init', 'disable_comments_admin_bar');

// Отключить RSS-ленты комментариев
function disable_comments_feed() {
    add_filter('feed_links_show_comments_feed', '__return_false');
    remove_action('wp_head', 'feed_links_extra', 3);
}
add_action('wp_head', 'disable_comments_feed');

// Скрыть ссылки на комментарии в head
remove_action('wp_head', 'feed_links', 2);


guest
Другие сообщения форума
Закрыть меню
ZAPLATA.RU | Магазин готовых блогов Wordpress с автонаполнением
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.