How do I alter the position of a Custom Post Type menu item within my plugin admin menu?

I’m writing a plugin (for the first time, so bear with me!) which includes a custom post type; ‘Programmes’. In the admin menu, I’ve set up a new menu group for the plugin, and I have the ‘Programmes’ menu item within that, along with some others. My problem is that the ‘Programmes’ item only seems to appear first, when I have an item called ‘Dashboard’ which I want to appear first. I’ve tried altering the ‘menu_position’ argument but that hasn’t made a difference (presumably this only applies to the top-level admin menu).

This is how my menu is rendering:

  • Hiblio
    • Programmes
    • Dashboard
    • Applications

Screenshot

Whereas this is how I’d like it to look:

  • Hiblio
    • Dashboard
    • Programmes
    • Applications

Here’s my arguments for the custom post type:

$args = array(
    'label'               => __( 'programmes', 'hiblio' ),
    'description'         => __( 'Programmes for application from partner organisations', 'hiblio' ),
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
    'taxonomies'          => array( 'programmes_categories' ),
    'hierarchical'        => true,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => 'hiblio',
    'show_in_nav_menus'   => false,
    'show_in_admin_bar'   => false,
    'menu_position'       => 2,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => true,
    'publicly_queryable'  => false,
    'capability_type'     => 'post'
);

Any ideas?

Thanks in advance,

Ash

1 Answer
1

As the dashboard uses the menu_position 2, just use menu_position 1.

so:

$args = array(
    'label'               => __( 'programmes', 'hiblio' ),
    'description'         => __( 'Programmes for application from partner organisations', 'hiblio' ),
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
    'taxonomies'          => array( 'programmes_categories' ),
    'hierarchical'        => true,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => 'hiblio',
    'show_in_nav_menus'   => false,
    'show_in_admin_bar'   => false,
    'menu_position'       => 1,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => true,
    'publicly_queryable'  => false,
    'capability_type'     => 'post'
);

Information by: Placing a custom post type menu above the Posts menu using menu_position?

Happy Coding,

Kuchenundkakao

Leave a Comment