Is it OK to move admin menu items?

I have a site with eight custom post types. Each is registered with 'menu_position' => 5 (below the Post menu). A side effect of having more than four CPTs is that the Media menu now appears in the middle of the list of CPTs (see image).

Admin menu with many custom post types

My solution is to duplicate the Media menu item in a lower position, then unset the original Media menu item:

add_action( 'admin_head', 'change_menu_items' );

function change_menu_items() {

    global $menu;

    $menu[14] = $menu[10];
    unset( $menu[10] );

}

My question is: is this likely to cause any unforeseen side effects? I haven’t come across any yet, but just wanted to make sure.

Thanks!

1 Answer
1

this might work:

add_filter('custom_menu_order', 'my_custom_menu_order');
add_filter('menu_order', 'my_custom_menu_order');

function my_custom_menu_order($menu_ord) {
    if (!$menu_ord) return true;
    return array(
        'index.php', // the dashboard link
        'edit.php?post_type=custom_post_type',
        'edit.php?post_type=page', 
        'edit.php' // posts
            // add anything else you want, just get the url
    );
}

Leave a Comment