Wordpress: Tắt tính năng bình luận

Tắt tính năng bình luận của worpdress để tránh spam và các lỗ hổng bảo mật liên quan

Thêm đoạn mã sau vào tập tin functions.php trong theme bạn sử dụng


add_action('admin_init', function () {
    // Redirect any user trying to access comments page
    global $pagenow;
    
    if ($pagenow === 'edit-comments.php') {
        wp_redirect(admin_url());
        exit;
    }

    // Remove comments metabox from dashboard
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');

    // Disable support for comments and trackbacks in post types
    foreach (get_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');
        }
    }
});

// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);

// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);

// Remove comments page in menu
add_action('admin_menu', function () {
    remove_menu_page('edit-comments.php');
});

// Remove comments links from admin bar
add_action('init', function () {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
});
  • 0 người thấy điều này hữu ích
Nội dung này có hữu ích không?

Những bài viết liên quan

How to Access the WordPress Admin Dashboard

WordPress is an easy to work with CMS software. To access a WordPress account, please follow...

How to Remove Sample Comments and Posts From WordPress

You get sample comments and posts in a fresh WordPress install. You can easily remove them in the...

How to Write and Publish Your First Blog Post in WordPress

Writing your first blog post is a fascinating thing. Follow the steps below to do so in...

How to Remove a Post in WordPress

You can remove the published or draft post in WordPress.1. Log in to the WordPress dashboard. 2....

How to Bulk Delete Posts in WordPress

It is possible to delete posts in bulk using WordPress. You can also delete selected posts in...

Powered by WHMCompleteSolution