编辑:更新WP 4.9和;仅隐藏编辑器的菜单项
如果希望用户能够更改导航菜单,但不能更改外观下的其他选项:请使用
// Do this only once. Can go anywhere inside your functions.php file
$role_object = get_role( \'editor\' );
$role_object->add_cap( \'edit_theme_options\' );
您可以在刷新管理面板后注释掉整个代码,因为上面的代码将对数据库进行持久更改。
现在,编辑器可以看到“外观”下的所有选项。您可以像这样隐藏其他选项:
function hide_menu() {
if (current_user_can(\'editor\')) {
remove_submenu_page( \'themes.php\', \'themes.php\' ); // hide the theme selection submenu
remove_submenu_page( \'themes.php\', \'widgets.php\' ); // hide the widgets submenu
remove_submenu_page( \'themes.php\', \'customize.php?return=%2Fwp-admin%2Ftools.php\' ); // hide the customizer submenu
remove_submenu_page( \'themes.php\', \'customize.php?return=%2Fwp-admin%2Ftools.php&autofocus%5Bcontrol%5D=background_image\' ); // hide the background submenu
// these are theme-specific. Can have other names or simply not exist in your current theme.
remove_submenu_page( \'themes.php\', \'yiw_panel\' );
remove_submenu_page( \'themes.php\', \'custom-header\' );
remove_submenu_page( \'themes.php\', \'custom-background\' );
}
}
add_action(\'admin_head\', \'hide_menu\');
中的最后3行
hide_menu()
函数是特定于我的主题的主题。通过单击管理面板中要隐藏的子菜单,可以找到第二个参数。然后,您的URL将类似于:example。com/wp管理员/主题。php?第页=
yiw_panel因此,在本例中remove_submenu_page()
功能将是yiw_panel