Adding Post Types and Taxonomies to Custom Admin Menu Pages

Customizing the WordPress admin menu is something you’ll eventually need to or want to do at some point. Customizing admin menus with Post Types is pretty easy compared to Taxonomies.

When you create Custom Post Types and Custom Taxonomies in WordPress using register_post_type(); and register_taxonomy(); there’s a parameter for each function called show_in_menu.

If you look at register_post_type(); the parameter accepts a simple true or false but also accepts a string as an argument for show_in_menu:

show_in_menu
(boolean or string) (optional) Where to show the post type in the admin menu. show_ui must be true.

Default: value of show_ui argument

‘false’ – do not display in the admin menu
‘true’ – display as a top level menu
‘some string’ – If an existing top level page such as 'tools.php' or 'edit.php?post_type=page', the post type will be placed as a sub menu of that.

Note: When using ‘some string’ to show as a submenu of a menu page created by a plugin, this item will become the first submenu item, and replace the location of the top-level link. If this isn’t desired, the plugin that creates the menu page needs to set the add_action priority for admin_menu to 9 or lower.

Note: As this one inherits its value from show_ui, which inherits its value from public, it seems to be the most reliable property to determine, if a post type is meant to be publicly useable. At least this works for _builtin post types and only gives back post and page.

If you look at register_taxonomy(); the parameter accepts a simple true or false but DOESN’T accept a string as an argument for show_in_menu like register_post_type(); does:

show_in_menu
(boolean) (optional) Where to show the taxonomy in the admin menu. show_ui must be true.
Default: value of show_ui argument

‘false’ – do not display in the admin menu
‘true’ – show as a submenu of associated object types

Adding a Custom Post Type to a custom admin menu is simple. Just specify the slug of the custom admin menu as an argument for the show_in_menu parameter while using register_post_type();.

How about adding a Custom Taxonomy to a custom admin menu? That’s a bit tricky to do.

What I’m about to show you works for both Custom Post Types AND Custom Taxonomies. So do with it what you please.

Step 1 – Hook into init and register Custom Post Types and Custom Taxonomies.

 

Step 2 – Hook into admin_menu to create a custom parent admin menu, and add Custom Submenu Admin Pages, Custom Post Type pages, and Custom Taxonomy Pages all to the custom parent admin menu.

 

Step 3 – Hook into parent_file to correctly highlight your Custom Post Type and Custom Taxonomy submenu items with your custom parent menu/page.

If you need any clarification about how any of this works, read the following pages from top to bottom:

  1. Adding Custom Parent Admin Menus
  2. Adding Custom Child Admin Menus
  3. Roles and Capabilities in WordPress
  4. Registering Custom Post Types
  5. Registering Custom Taxonomies
  6. WordPress Plugin API :: Action Reference
  7. WordPress Plugin API :: Action Reference :: init
  8. WordPress Plugin API :: Action Reference :: admin_menu
  9. WordPress Plugin API :: Filter Reference
  10. List of All WordPress Hooks (including actions and filters)

Credits

Original question asked by @numediaweb on WordPress Stack Exchange: Show custom taxonomy inside custom menu.
Answer to Question: Show custom taxonomy inside custom menu by @Michael Ecklund on WordPress Stack Exchange.

Related Questions

This article assists in answering all of the following related questions:

  1. [WordPress Development] Show custom taxonomy inside custom menu asked by: @numediaweb
  2. [WordPress Development] How do I create multiple post types in same menu section in WP-admin? asked by: @Peter Westerlund
  3. [WordPress Development] Show custom taxonomies in admin panel under custom post type asked by: @Eoghan OLoughlin
  4. [WordPress Development] How to add a taxonomy into admin menu asked by: @genuy11512

Leave a Reply