Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress: Change admin submenu order

Tags:

php

wordpress

I have created and registered an admin page as a sub-menu under 'Posts' admin menu. But the problem is its coming at the end of the wp-submenus(ie., after 'Tags'),

How to change the order of this custom admin page submenu entry to appear after 'Add new' ?

I'm using this function to register my sub-menu under edit.php(Posts menu)

add_submenu_page( 
       'edit.php', 
       "my custom submenu", 
       "my custom submenu", 
       CAPABILITY, 
       'my_custom_submenu', 
       "scrollcore_newsroom_articles" 
     );
like image 634
Nagendra Rao Avatar asked Sep 12 '13 14:09

Nagendra Rao


Video Answer


1 Answers

Found the solution, just need to add this function to your functions.php

/*Change menu-order*/

add_filter( 'custom_menu_order', 'so_18766477_submenu_order' );

function so_18766477_submenu_order( $menu_ord ) 
{
    global $submenu;

    // Enable the next line to see all menu orders
    //echo '<pre>'.print_r($submenu,true).'</pre>';

    $arr = array();
    $arr[] = $submenu['edit.php'][5];     //my original order was 5,10,15,16,17,18
    $arr[] = $submenu['edit.php'][10];
    $arr[] = $submenu['edit.php'][18];
    $arr[] = $submenu['edit.php'][17];
    $arr[] = $submenu['edit.php'][15];
    $arr[] = $submenu['edit.php'][16];
    $submenu['edit.php'] = $arr;

    return $menu_ord;
}

Here by choosing edit.php, I'm targeting 'Posts' menu. You can choose any file that you want its sub-menu to be reordered, like plugins.php, themes.php, tools.php etc

like image 132
Nagendra Rao Avatar answered Sep 19 '22 17:09

Nagendra Rao