Skip to content

Instantly share code, notes, and snippets.

@junaidtk
Created February 8, 2019 03:48
Show Gist options
  • Select an option

  • Save junaidtk/00580234a57c79e978ed479d296fa54e to your computer and use it in GitHub Desktop.

Select an option

Save junaidtk/00580234a57c79e978ed479d296fa54e to your computer and use it in GitHub Desktop.
Add post type menu as admin_sub_menu
// 1. when registering a custom post type set show_in_menu to false,
function ttlm_register_team_custom_type() {
$labels = array(
'name' => _x( 'Teams', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Team', 'post type singular name', 'your-plugin-textdomain' ),
'menu_name' => _x( 'Teams', 'admin menu', 'your-plugin-textdomain' ),
'name_admin_bar' => _x( 'Team', 'add new on admin bar', 'your-plugin-textdomain' ),
'add_new' => _x( 'Add New', 'team', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Add New Team', 'your-plugin-textdomain' ),
'new_item' => __( 'New Team', 'your-plugin-textdomain' ),
'edit_item' => __( 'Edit Team', 'your-plugin-textdomain' ),
'view_item' => __( 'View Team', 'your-plugin-textdomain' ),
'all_items' => __( 'All Teams', 'your-plugin-textdomain' ),
'search_items' => __( 'Search Teams', 'your-plugin-textdomain' ),
'parent_item_colon' => __( 'Parent Teams:', 'your-plugin-textdomain' ),
'not_found' => __( 'No teams found.', 'your-plugin-textdomain' ),
'not_found_in_trash' => __( 'No teams found in Trash.', 'your-plugin-textdomain' )
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => false, //<--- HERE
'query_var' => true,
'rewrite' => array( 'slug' => 'ttlm_team' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'ttlm_team', $args );
}
add_action( 'init', 'ttlm_register_team_custom_type' );
// 2. when adding a sub-menu page set the callback function to NULL and
// set the menu_slug to the appropriate custom post type url
// (in this case it's edit.php?post_type=ttlm_team)
add_submenu_page( 'ttlm', 'TTLM Teams', 'Teams',
'manage_options', 'edit.php?post_type=ttlm_team', NULL );
when registering a custom post type set the ‘show_in_menu’ argument to false,
when adding a sub-menu item set the callback function to NULL and the menu_slug to the custom post type,
e.g. ‘edit.php?post_type=your_custom_post_type_name_goes_here’
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment