WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am adding items to a CPT Admin menu using add_submenu_page which works great, but they are added to the bottom of the sub-menu after the CPT options. I want to be able to have them on top , but I suppose this question can also apply to ordering all Admin based sub-menu items.

What I tried ( not working, I tried several variations),

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

       return array( 

         'edit.php?post_type=page' =>array(

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

Would this be because menu_order filter does not take sub-menu's into account?

share|improve this question
up vote 3 down vote accepted

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]);
add_action('_admin_menu', 'custom_menu_order');
share|improve this answer
It's ugly but it will have to do. – Wyck Sep 19 '11 at 4:07
Actually this won't do, the array keys bounce all over the place. – Wyck Sep 19 '11 at 4:29
I got it to work by traversing the array. The saving grace here is zero is not used as a key for the sub items on a menu. – Brian Fegter Sep 19 '11 at 13:37
This will only work on pages added through the add_submenu_page() function. Core subs like Theme Editor, etc... can't be touched here. – Brian Fegter Sep 19 '11 at 13:42
Ya this does work, before I was just using key value, thanks. I want to add that it was not working with the _admin_menu or menu_order filter for some reason but it does work with custom_menu_order – Wyck Sep 19 '11 at 19:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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