How can I control the position in the admin menu of items added by plugins?

To change top level admin menu items order you’ll need two hooks, two filters, and one function. Put the following code in your current theme’s functions.php:

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

    return array(
        'index.php', // Dashboard
        'separator1', // First separator
        'edit.php', // Posts
        'upload.php', // Media
        'link-manager.php', // Links
        'edit-comments.php', // Comments
        'edit.php?post_type=page', // Pages
        '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', 'wpse_custom_menu_order', 10, 1 );
add_filter( 'menu_order', 'wpse_custom_menu_order', 10, 1 );

The returned array of top level admin menu items, above, represents menu items inserted by core, in their default order. To include menu items added by plugins, we have to add them to this array. Let’s say we have two plugins added and activated ( for example: Wordfence and NextCellent Gallery ). We have to find names of these menu items, first. When we click on Wordfence‘s top level menu item, the resulting URL will end with ?page=Wordfence. The part after ?page= is our name ( Wordfence ). For NextCellent Gallery, the name will be nextcellent-gallery-nextgen-legacy. Now, let’s add these items to our array:

return array(
    'index.php', // Dashboard
    'separator1', // First separator
    'edit.php', // Posts
    'upload.php', // Media
    'link-manager.php', // Links
    'edit-comments.php', // Comments
    'edit.php?post_type=page', // Pages
    'separator2', // Second separator
    'themes.php', // Appearance
    'plugins.php', // Plugins
    'users.php', // Users
    'tools.php', // Tools
    'separator3', // Third separator
    'options-general.php', // Settings
    'separator-last', // Last separator
    'Wordfence', // Wordfence
    'nextcellent-gallery-nextgen-legacy', // NextCellent Gallery
);

We can, now, move items of this array, up and down, to get the final order.

Note: you can use Admin Menu Editor plugin, for easy drag and drop actions, as well.

Leave a Comment