1

I would like to change the priority/menu order of the "Media" admin page. Is there a way to change that via apply_filter?

Is there a way to change only "Media" page priority without having to list all pages within menu_order?

Thanks

4

There's a combination of two filters, menu_order does the job, but you also use custom_menu_order to enable menu_order.

function wpse_233129_custom_menu_order() {
    return array( 'index.php', 'upload.php' );
}

add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'wpse_233129_custom_menu_order' );

This will put upload.php (the Media screen) just after the Dashboard and then the other top-level menu items will follow.

If you want to put Media elsewhere then just list all the other screens that should precede it in the array.

Alternatively you could directly address WP's global $menu array:

function wpse_233129_admin_menu_items() {
    global $menu;

    foreach ( $menu as $key => $value ) {
        if ( 'upload.php' == $value[2] ) {
            $oldkey = $key;
        }
    }

    $newkey = 26; // use whatever index gets you the position you want
    // if this key is in use you will write over a menu item!
    $menu[$newkey]=$menu[$oldkey];
    $menu[$oldkey]=array();

}
add_action('admin_menu', 'wpse_233129_admin_menu_items');

Note the comment on the possibility of overwriting another menu item. Coding in a search for an array index that doesn't collide is left as an exercise for the reader. This isn't an issue if you use the first method, of course.

There's something about fiddling with WP's globals like this that makes me feel dirty. Changes to WP's inner workings can mess things up for you. Use the abstractions provided by hooks and APIs when you can.

| improve this answer | |
  • Yes, that's also what I was able to find. However, is there a way to do that without listing all of them? I have bunch of custom types as well. Just need to change the priority of the media page :) – Spiro Jul 25 '16 at 12:56
  • I've expanded my answer. – Andy Macaulay-Brook Jul 25 '16 at 13:08
  • Good workaround, but it seems that the menu is rendered the same way. Also it should check if the new key is already existent to prevent overwriting another menu item. However, it doesn't seem to work for me. – Spiro Jul 25 '16 at 13:31
  • Ah, hence my comment about the danger of messing with globals - something might have changed since I once did this back on about WP 3.something. You're right about the collision of course, I'll edit for that. – Andy Macaulay-Brook Jul 25 '16 at 13:37
  • I've tested and corrected the code. I still think using the filter is better, as although the second method allows you to specify your required position, someone's plugin can always add a menu item in above. – Andy Macaulay-Brook Jul 25 '16 at 14:08
1

A quick Google Search gave me several results and I managed to find an easy solution.

The code below is from Easy Web Design Tutorial website but I will paste it below in case that link ever breaks.

function reorder_admin_menu( $__return_true ) {
    return array(
         'index.php', // Dashboard
         'edit.php?post_type=page', // Pages
         'edit.php', // Posts
         'upload.php', // Media
         'themes.php', // Appearance
         'separator1', // --Space--
         'edit-comments.php', // Comments
         'users.php', // Users
         'separator2', // --Space--
         'plugins.php', // Plugins
         'tools.php', // Tools
         'options-general.php', // Settings
   );
}
add_filter( 'custom_menu_order', 'reorder_admin_menu' );
add_filter( 'menu_order', 'reorder_admin_menu' );

You can re-order the menu by simply moving media.php where you would like it to be displayed

As you can see the code above is well commented and shows you which .php files is what link :)

| improve this answer | |
  • 4
    Yes, that's also what I was able to find. However, is there a way to do that without listing all of them? I have bunch of custom types as well. Just need to change the priority of the media page :) – Spiro Jul 25 '16 at 12:56
0

After getting repeat PHP errors with the above code I went with a plugin,
Admin Menu Editor. Not only can I reorder menus it also lets me hide or move menus added by plugins.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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