Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
tommcfarlin
/
add-custom-post-type-menu.php
Created
April 25, 2013 12:38
Star
24
Fork
15
Star
Code
Revisions
1
Stars
24
Forks
15
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
[WordPress] Add a custom post type menu as a child of an existing custom post type menu.
Raw
add-custom-post-type-menu.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
<?php
// Define the 'Portfolio' post type. This is used to represent galleries
// of photos. This will be our top-level custom post type menu
$args = array(
'labels' => array(
'all_items' => 'Gallery',
'menu_name' => 'Portfolio',
'singular_name' => 'Gallery',
'edit_item' => 'Edit Gallery',
'new_item' => 'New Gallery',
'view_item' => 'View Gallery',
'items_archive' => 'Gallery Archive',
'search_items' => 'Search Portfolio',
'not_found' => 'No galleries found',
'not_found_in_trash' => 'No galleries found in trash'
),
'supports' => array( 'title', 'editor', 'author', 'revisions' ),
'menu_position' => 5,
'public' => true
);
register_post_type( 'portfolio', $args );
// Next, we'll define a second custom post type called 'Locations' where we could
// potentially display a list of locations that are used as part of our portfolio.
// 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', // This is where we tell WordPress to add 'Locations' as a submenu
'public' => true
);
register_post_type( 'location', $args );
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.