在WordPress后臺(tái)移除“評(píng)論”菜單,可以通過(guò)以下幾種方法實(shí)現(xiàn)。以下是詳細(xì)步驟:

方法1:通過(guò)代碼移除(推薦)

將以下代碼添加到主題的functions.php文件中(或使用CodeSnippets插件):

// 移除后臺(tái)左側(cè)菜單的“評(píng)論”
add_action('admin_menu', 'remove_comments_menu');
function remove_comments_menu() {
    remove_menu_page('edit-comments.php'); // 移除頂級(jí)菜單
}

// 可選:同時(shí)移除工具欄(頂部管理?xiàng)l)中的評(píng)論鏈接
add_action('admin_bar_menu', 'remove_comments_from_admin_bar', 999);
function remove_comments_from_admin_bar($wp_admin_bar) {
    $wp_admin_bar->remove_node('comments');
}

方法2:通過(guò)角色權(quán)限控制(隱藏評(píng)論)

如果希望僅對(duì)特定用戶角色隱藏評(píng)論(如作者、編輯),可以限制其權(quán)限:

// 禁止特定角色訪問(wèn)評(píng)論功能
add_action('init', 'disable_comments_for_roles');
function disable_comments_for_roles() {
    $role = get_role('author'); // 替換為目標(biāo)角色
    if ($role) {
        $role->remove_cap('moderate_comments');
        $role->remove_cap('edit_comment');
    }
}

方法3:使用插件(簡(jiǎn)單但可能冗余)

安裝插件如”DisableComments”,但注意這會(huì)全局禁用評(píng)論功能(包括前端),可能不符合僅需隱藏菜單的需求。

注意事項(xiàng)

備份代碼:修改functions.php前先備份。

子主題:如果使用第三方主題,建議通過(guò)子主題或插件(如CodeSnippets)添加代碼,避免更新覆蓋。

權(quán)限問(wèn)題:管理員(Administrator)默認(rèn)仍可訪問(wèn),如需完全禁用需額外調(diào)整權(quán)限。

效果驗(yàn)證

登錄后臺(tái)后,左側(cè)菜單的“評(píng)論”選項(xiàng)應(yīng)消失。

直接訪問(wèn)wodepress.com/wp-admin/edit-comments.php會(huì)提示權(quán)限不足(非管理員)。