You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用Gutenberg侧边栏的“置顶博客”与“待审核”选项

WordPress禁用/隐藏文章侧边栏置顶、待审核选项方法

方案1:PHP代码彻底禁用对应功能(推荐)

直接从底层移除对应功能支持,完全生效无残留。将以下代码添加到当前使用主题的functions.php文件末尾,或者站点的自定义功能插件中即可:

// 移除文章类型的置顶功能支持,隐藏侧边栏置顶选项
add_action('init', function () {
    unregister_post_type_support('post', 'sticky');
});

// 禁用文章待审核状态,对非管理员用户隐藏该选项
add_filter('register_post_status', function ($status, $handle) {
    if ($handle === 'pending' && !current_user_can('manage_options')) {
        $status->public = false;
        $status->show_in_admin_status_list = false;
        $status->show_in_admin_all_list = false;
    }
    return $status;
}, 10, 2);

如果需要管理员也看不到待审核选项,删除上述代码中&& !current_user_can('manage_options')的判断条件即可。

方案2:后台CSS仅视觉隐藏(轻量灵活)

如果只是不想让普通用户看到选项,不需要彻底禁用功能,可以用CSS隐藏的方案,修改起来更灵活。将以下代码添加到主题的functions.php文件末尾即可:

// 给文章编辑页插入自定义CSS隐藏指定选项
add_action('admin_head-post.php', 'hide_custom_editor_options');
add_action('admin_head-post-new.php', 'hide_custom_editor_options');
function hide_custom_editor_options() {
    echo <<<CSS
    <style>
        /* 隐藏置顶选项 */
        .editor-post-sticky {
            display: none !important;
        }
        /* 隐藏待审核状态选项 */
        .components-select-control__option[value="pending"] {
            display: none !important;
        }
    </style>
    CSS;
}

两种方案兼容WordPress 5.8及以上所有版本,修改后清空后台缓存即可生效。

内容的提问来源于stack exchange,提问作者Hashim Aziz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 05:09:03