Order Admin sub-menu items?

The filter ‘custom_menu_order’ will not work on the menu order because apply_filters in wp-admin/includes/menu.php supplies false as the filtered content. You can try changing false to $menu and the filter works grand.

Since we obviously can’t touch the core, here’s how I got it to work:

function custom_menu_order(){
    global $submenu;

    $find_page="edit.php";
    $find_sub = 'Post Tags';

    foreach($submenu as $page => $items):
        if($page == $find_page):
            foreach($items as $id => $meta):
                if($meta[0] == $find_sub):
                    $submenu[$find_page][0] = $meta;
                    unset ($submenu[$find_page][$id]);
                    ksort($submenu[$find_page]);
                endif;
            endforeach;
        endif;
    endforeach;
}
add_action('_admin_menu', 'custom_menu_order');

Leave a Comment