add_submenu_page() appearing on top of sub menu instead of bottom

Viewed 3498

I am using add_submenu_page to add a sub-level menu to a post type.

The problem is that the sub level menu "Batches" appears on top of the post type name "Offline Course" but I want it to appear at the bottom

enter image description here

// Register Custom Post Type
function register_offline_course() {

    $argscourse = array(
        'label'                 => __( 'Offline Course', 'Offline Course' ),
        'supports'              => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', ),
        'taxonomies'            => array( 'offline_course_cat' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => false,       
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'course_offline', $argscourse );

    $argsbatch = array(
        'label'                 => __( 'Batch', 'Batch' ),
        'supports'              => array( 'title','revisions', ),
        'taxonomies'            => array( 'offline_course_cat' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => false,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => false,       
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'course_batches', $argsbatch );

    add_submenu_page( 'edit.php?post_type=course_offline', 'Batches', 'Batches',
    'manage_options', 'edit.php?post_type=course_batches', NULL );
}
add_action( 'init', 'register_offline_course', 0 );
3 Answers

FOR THOSE who want the sub level menu to APPEAR IN THE MIDDLE.

I am posting this here because that's what I wanted and Google led me to this page.

I wanted my plugin's sub menu to look like this:

  • Items
  • Categories

(any number of sub menu items here; inserted by add-ons)

  • Settings

What I ended up with is writing the code in the main plugin like this:

//I am creating my plugin's sub-menu in two parts: top with priority = 10 and bottom with priority = 90
add_action('admin_menu', 'myplugin_configure_admin_menu_1',10);
add_action('admin_menu', 'myplugin_configure_admin_menu_2',90);

function myplugin_configure_admin_menu_1(){
   //items      
   add_submenu_page('Parent name', 'item_redirect', 'Items', 'administrator',  'edit.php?post_type=myposstype');

   //categories
   add_submenu_page('Parent name', 'category_redirect', 'Categories', 'administrator',  'edit-tags.php?taxonomy=mycategory&post_type=myposstype');
}

function myplugin_configure_admin_menu_2(){ 
   //settings
    add_submenu_page('Parent name', 'settings', 'Settings', 'administrator',  'admin.php?page=Parent name&tab=welcome');
}

And then, in my add-ons

//priority is 10-90    
add_action('admin_menu', 'myaddon_configure_admin_menu',20);

function myaddon_configure_admin_menu(){
   //add some other sub menu item
}
Related