I’m trying to rearrange my admin menu so I can remove the submenus.
Basically I’m starting by removing all submenus that I don’t want (for instance the ones under the “home” button, or the ones under the “posts” buttons), then I add new entries to the $menu array.
my code looks like this (example is for the update entry but I’ve done so for the categories and link categories too):
function setAdminMenu (){
/* unsetting the home subemnus */
unset($submenu['index.php'];
/* adding the update link at a top-level position */
$menu[3] = array( __('Updates'), 'read', 'update-core.php', '', 'menu-top menu-top-first', 'menu-maj', 'div' );
}
It seems to work well, except that submenus are still acting as ones: when one clicks on the “updates” menu button, the button doesn’t stay active but another one (the “tools” button as well as its submenus which I have kept), or when one clicks on the “categories” menu it’s the “posts” entry that is shown clicked.
It’s odd because I think I gave the appropriate classes to the menu item but when I have a look at the source code, I see that it’s the “parent” button of the buttons that gets the .current class (which manages the “clicked” appearance).
How do I fix the problem? Is it possible? I think that maybe it’s the way some of the admin pages work?
EDIT
Hi Wyck and thank you for your answer but actually my problem is not to add or remove some items from the menu and submenu but the way thing goes once it’s done.
More precisely, i’ve deleted all submenus, took some elements which were on those submenus and put them in the main menu. for instance I removed the “updates” link from the “dashboard” (index.php) submenu and put it as a top-level menu. And done the same with Links Categories and posts categories.
Thing is it’s working, I have the menu I want to have (no submenus) but when I click on the elements which were on submenus, instead of having their button act as the ones which have always been on top-level, they act as they were in submenus.
To be more clear, I’ve defined the “clicked” (and hover etc) state of the buttons: they change color. When I click on the “updates” button in my new configuration (or on the “categories” or “link categories”), instead of taking the clicked state, the buttons take no state at all, and instead it’s the button they used to be related to when they were in submenus that takes the clicked state, though it goes to the apropriate page.
I saw that when you click on a button in the menu, wordpress adds a .current class to it, it works for all elements which are in the original top-level menu, but not for the ones which are normally on submenus and I don’t know how to bipass that (maybe with a js?)
There is no easy to way do this, I answered this question with a code example on WPSE recently, but I cannot find it.
Basically what you have to do for sub-menu items ordering is remove them all, then add them in the order you want.
So first you have a function to remove them:
Then you use
add_submenu_page
and add them in the order you want. http://codex.wordpress.org/Function_Reference/add_submenu_pageIt seems convenluted and it is, the alternative is something wacky like this, Order Admin sub-menu items?
This is for sub-menu items, for top level items, use
remove_menu_page
Edit
Index.php
is not submenu item , it is a top level item so you title is confusing!, to order top level items use this answer, https://wordpress.stackexchange.com/a/1568/1509