Question

I am trying to add submenu under my custom post type and i succeeded also but it shows just under the post-type, i want to show it under the taxonomy. How to give a position to the newly created sub-menu?

And one more problem raised: on clicking taxonomies the parent menu block is not stays activated.

enter image description here

Here is my code.

<?php
add_submenu_page('edit.php?post_type=car', "Package Layout Setting", "Layouts", "manage_options", "layout", "car_product_layout_setting", '');

function car_product_layout_setting() {
    ?>
    <div class="wrap">
        <h1>Package Layout Setting</h1>
    </div>
    <?php
}
Était-ce utile?

La solution

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;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top