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
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.
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 :)
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.