How to give position to Submenu under custom post type

If you connect your functions with proper hooks your submenu page will be displayed after your post type and taxonomy. Take a look at my example:

/**
 * Register event post type
 *
 * Function is used by init hook
 */
function wpse_288373_register_event_post_type() {

    $labels = array(
        'name' => __( 'Events' ),
        'singular_name' => __( 'Event' ),
        'add_new' => __( 'Add new' ),
        'add_new_item' => __( 'Add new' ),
        'edit_item' => __( 'Edit' ),
        'new_item' => __( 'New' ),
        'view_item' => __( 'View' ),
        'search_items' => __( 'Search' ),
        'not_found' => __( 'Not found' ),
        'not_found_in_trash' => __( 'Not found Events in trash' ),
        'parent_item_colon' => __( 'Parent' ),
        'menu_name' => __( 'Events' ),

    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => false,
        'supports' => array( 'title', 'page-attributes' ),
        'taxonomies' => array(),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => false,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => array('slug' => 'event'),
        'capability_type' => 'post',
    );

    register_post_type( 'event', $args );
}

add_action( 'init', 'wpse_288373_register_event_post_type' );

/**
 * Register submenu
 *
 * Function is used by admin_menu hook
 */
function wpse_288373_register_submenu_page() {
    add_submenu_page('edit.php?post_type=event', 'Event settings', 'Settings', "manage_options", 'settings', 'wpse_288373_event_settings', '');
}

add_action('admin_menu', 'wpse_288373_register_submenu_page');

/**
 * Register submenu page
 *
 * Function is used by add_submenu_page function
 */
function wpse_288373_event_settings() {
    return;
}

Leave a Comment