Is there a function I can use which will temporarily output the menu_position of every item in the admin menu?

While trying to reorganise the admin menu, the single largest thing slowing me down is trying to mentally keep track of which menu item is where.

Being able to see this info while im doing this would be so helpful!


2 Answers 2


I've just finished a plugin that (amongst other things) allows the reordering of the admin menu. The way the admin menu is constructed is not the easiest thing to work with at all. That being said have a look at the admin_menu hook. You can access the global $menu array at that point - which is an array containing each menu item - each of which is an array containing all the details of that item. You can then do something like:

 * Prints the global $menu array
 * The elements in each item array are :
 * 0: Menu title
 * 1: Minimum level or capability required.
 * 2: The URL of the item's file
 * 3: Page Title
 * 4: Classes
 * 5: ID
 * 6: Icon for top level menu
 * @global array $menu
add_action( 'admin_menu', 'wpse_217154_print_admin_menu', 10 );
function wpse_217154_print_admin_menu() {

    global $menu;

    echo '<pre>';
    echo '</pre>';

Well, as always, after looking for a while and not finding anything, after posting here I found a solution almost immediately here.

function custom_menu_order($menu_ord) {
    if (!$menu_ord) return true;

    return array(
        'index.php', // Dashboard
        'separator1', // First separator
        'edit.php?post_type=custom-post-slug' // Custom post slug
        'edit.php', // Posts
        'upload.php', // Media
        'link-manager.php', // Links
        'edit.php?post_type=page', // Pages
        'edit-comments.php', // Comments
        'separator2', // Second separator
        'themes.php', // Appearance
        'plugins.php', // Plugins
        'users.php', // Users
        'tools.php', // Tools
        'options-general.php', // Settings
        'separator-last', // Last separator
add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order
add_filter('menu_order', 'custom_menu_order');

This also seems to work with custom post types - note the third item inside the return array, which is the slug of a custom post type I created.

If you leave any menu item out of that array, the menu item will appear at the end of the list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.