plugin development - Adding parent custom post type menu option

admin2025-05-31  0

random problem for me here. I have several custom post types registered to Wordpress and I want to add the archive pages to the menu, but I do not want them to be static links.

Is there any way to add the custom post types to the Wordpress menu via plugin etc and have the hiearchical menu classes stuff work nicely?

E.G I have a jobs CPT which I want to just add a jobs menu item for which will just link to the archive for that CPT.

random problem for me here. I have several custom post types registered to Wordpress and I want to add the archive pages to the menu, but I do not want them to be static links.

Is there any way to add the custom post types to the Wordpress menu via plugin etc and have the hiearchical menu classes stuff work nicely?

E.G I have a jobs CPT which I want to just add a jobs menu item for which will just link to the archive for that CPT.

Share Improve this question asked Jul 28, 2013 at 19:35 DavidDavid 3412 gold badges4 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Use the param 'show_in_menu' in the function register_post_type() to add this CPT to the menu. Also it is possible to use as submenu in a existing or created menu item. Now a example to add this as submenu in a existing Custom Post Type.

// This custom post type will be added as a submenu to the 'Portfolio' menu
$args = array(
  'labels' => array(
        'all_items'           => 'Locations',
        'menu_name'           => 'Locations',
        'singular_name'       => 'Location',
        'edit_item'           => 'Edit Location',
        'new_item'            => 'New Location',
        'view_item'           => 'View Location',
        'items_archive'       => 'Location Archive',
        'search_items'        => 'Search Locations',
        'not_found'           => 'No locations found.',
        'not_found_in_trash'  => 'No locations found in trash.'
    ),
    'supports'      =>  array( 'title', 'editor', 'revisions' ),
    'show_in_menu'  =>  'edit.php?post_type=portfolio',
    'public'        =>  TRUE
);
register_post_type( 'location', $args );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748629428a313644.html

最新回复(0)