Is it possible to set the position of an item in the admin menu? I’m trying to move the media link under my custom post types. I know that the media link is position 10. Is it possible to set it to 14?
I know that I can change the position of all the links using the custom_menu_order
filter but I’m not seeing a way to set the position in that filter.
This is not an exact answer, but I think there are enough elements to build the desired output.
I sort the menu manipulating the global
$menu
, not really best practice, but for now it works.The result of this example is moving Links Manager, Comments and Media Library to the end of the first block. The effect is: first all Post Types then these items.
We need a recursive array search function to locate the key of each item,
[5]
,[10]
,[15]
, etc. This way we can be sure of being targeting the right item and don’t need to inspect the menu to confirm each one’s key.The first thing is to grab the position of the second separator (
separator2
), as we are going to move everything just before it. Then we search for each item that we want to move, make a copy of it and unset from the$menu
. Finally, we subtract the number of “movable” items from the position of the separator (say 100) and add our items in the positions 97, 98, 99 (in this example we’re moving 3 items).I know, that’s an old one here, but the following solution is actually quite a bit nicer, i think:
Do a var_dump on $menu_order_string before the replace to see the positions and choose your position for the str_replace. In this very case, we’re repositioning the media library right behind the dashboard.
Hope this’ll help somebody in the future.