I’m not able to reorder WP Admin menu items when pages added with add_menu_page
have complicated slugs. At least I think that’s the problem…
First I create the custom menu items, which is working as expected:
function sma_simplify_admin_ui() {
global $user_ID;
if ( $user_ID != 1 ) {
add_menu_page( 'Menu', 'Menu', 'edit_posts', 'nav-menus.php?action=edit&menu=16', '', 'dashicons-menu' );
add_menu_page( 'Memberships', 'Memberships', 'edit_posts', 'edit.php?post_type=wc_user_membership', '', 'dashicons-groups' );
}
}
add_action( 'admin_init', 'sma_simplify_admin_ui' );
The new items cannot be reordered. If I put the exact slugs given when they were created, menu_order
(and custom_menu_order
) simply ignore them and my new items are always at the bottom of the menu.
function sma_reorder_admin_ui($menu_ord) {
if (!$menu_ord) return true;
return array(
'nav-menus.php?action=edit&menu=16',
'edit.php?post_type=wc_user_membership',
/* truncated for clarity, there is more stuff */
);
}
add_filter( 'custom_menu_order', 'sma_reorder_admin_ui' );
add_filter( 'menu_order', 'sma_reorder_admin_ui' );
Setting a priority when I create them isn’t letting me reorder them either, which is really weird…
I’m theorising the slug expected by custom_menu_order
& menu_order
isn’t what I’m giving it, but I don’t know what to give it. I’ve also tried every single slug/key/thing that I get when I vardump $GLOBAL['menu']
.
Please help me work out how to reorder my menu items!