I'm planning to use a couple of custom post types for a plugin of mine. The whole plugin should reside under 1 toplevel menu item. Thus I would prefer a menu structure like so:
- Dashboard
- Posts
- [...]
My Plugin
- Custom Post Type #1
- Custom Post Type #2
- [...]
This is possible by including 'show_in_menu' => 'my_plugin_toplevel_menu_item_slug'
in register_post_type
when registering my custom post types. Howerer, there are a few issues I've come across using this method.
- I have no say in how the title should be outputted. I would prefer to use
<h2 class="nav-tab-wrapper"> ... </h2>
, but now post.php prints the h2 output for me, and I don't know an easy way of overriding this. It is possible to do this with javascript as soon as the page is loaded, but this is a bit ugly in my opinion. - When using
'show_in_menu'
, the submenu page order cannot be altered. The custom post types are placed at the top automatically, because I guess Wordpress just gets to it quicker than I do. - The h2 icon disappears for some reason (I haven't really looked into this yet though, it might be very easy to solve).
Does anybody have an idea how to tackle these issues elegantly?
Update
See temporary solution in my answer below.
$submenu
is the only way to do this. You should add your solution as an Answer.show_in_menu
to true (for compatibility with other CPT-related plugins), useremove_menu_page()
to remove menu item, useadd_submenu_page()
to add back to the correct location and with a custom page title.