WordPress移除样板、自定义、字体这3个菜单
34
在WordPress后台移除“样板”(Patterns)、“自定义”(Customize)、“字体”(Font Library)这三个菜单项,你可以在当前主题的functions.php文件中添加以下代码:
/**
* 移除 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 钩子做重定向