如果像OP一样,您只想将菜单和小部件从外观移到顶层,那就更简单了。这也是我所需要的。
因为我们只是移动WP核心菜单项,所以不需要使用add_menu_page
要重新添加菜单项,我们不会添加任何新菜单项。只需从$子菜单数组中取消设置它们,然后在$菜单数组的其他位置重新设置它们。
function re_sort_menu() {
global $menu;
global $submenu;
// Note: find the position of every submenu in Appearance by uncommenting the following:
// print_r($submenu[\'themes.php\'];
unset($submenu[\'themes.php\'][10]); // Unsets Appearance -> Menu (position 10)
unset($submenu[\'themes.php\'][7]); // Unsets Appearance -> Widgets
// Add Menu and Widgets back at top level with some dashicons
// Be careful not to give menu positions (array keys) that conflict with other menu items
// TIP: print_r($menu); to see existing menu positions and also to check out the proper order of these array values. WP docu seems to list them in the incorrect order.
$menu[31] = array( __( \'Menus\', \'theme-slug\' ), \'edit_themes\', \'nav-menus.php\', __( \'Menus\', \'theme-slug\' ), \'menu-top menu-nav\', \'menu-nav\', \'dashicons-menu\');
$menu[32] = array( __( \'Widgets\', \'theme-slug\' ), \'edit_themes\', \'widgets.php\', __( \'Widgets\', \'theme-slug\' ), \'menu-top menu-nav\', \'menu-nav\', \'dashicons-admin-generic\');
}
add_action( \'admin_menu\', \'re_sort_menu\' );
上面诺克罗斯的回答让我走上了正确的道路,但不管出于什么原因
add_menu_item
在WP 4.1中,没有将正在工作的“Nav Menu”部分重新生成为“admin for me”中的顶级菜单项。问题似乎在于传递给该函数的数组值的顺序,但无论我如何重新排序,都会直接从新
WP Developer API article, 我从来没有让它工作过。