最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - Adding parent custom post type menu option

matteradmin7PV0评论

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 );
Post a comment

comment list (0)

  1. No comments so far