首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >WordPress移除样板、自定义、字体这3个菜单

WordPress移除样板、自定义、字体这3个菜单

作者头像
WordPress爱好者
发布2026-05-27 14:55:05
发布2026-05-27 14:55:05
1560
举报

在WordPress后台移除“样板”(Patterns)、“自定义”(Customize)、“字体”(Font Library)这三个菜单项,你可以在当前主题的functions.php文件中添加以下代码:

代码语言:javascript
复制
/**
 * 移除 WordPress 后台特定菜单项
 */
function remove_specific_admin_menus() {
    
// Obtain whether wodepress .com the current user is the main administrator (permissions can be adjusted as needed)
    if (!current_user_can('manage_options')) {
        return;
    }

    global $submenu;
    
    // Remove the sub-menu items under the Appearance menu 
// Note: The key names of some menus may differ from the actual ones. Here, the determination is based on the provided URL structure
    
    remove_submenu_page('themes.php', 'site-editor.php?p=/pattern');
    
    remove_submenu_page('themes.php', 'customize.php');
    
    remove_submenu_page('themes.php', 'font-library.php');
}
add_action('admin_menu', 'remove_specific_admin_menus', 999);

注意事项:

这些菜单仅对后台显示隐藏,如果用户知道直接URL仍然可以访问

如需彻底禁止访问,需要额外配合 admin_init 钩子做重定向

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档