I am trying to create a plugin, with a Dashboard page, config page, some extra pages for configuration and some custom post types.
More specific, in the admin I like to have some pages added in the menu via the functions add_menu_page and add_submenu_page, as well I like to create some custom post types related to the plugin.
The question is, how to group the custom post types menus under the plugin menu options.
In example, lets say I creating the menu option "MyPlugin" with the function add_menu_page and then below this menu I adding the pages "Settings Page", "Do stuff page", "Dashboard" via the function add_submenu_page and then I create the custom post type "Cars". How can I place the "Cars" menu under the MyPlugin menu option ?
The final result I like to be like that :
Dashboard
Home
...
Posts
All Posts
...
Settings
General
...
...
MyPlugin <- How to add this menu structure ?
Dashboard <- How to add this menu structure ?
Cars <- How to add this menu structure ?
Settings Page <- How to add this menu structure ?
Do stuff page <- How to add this menu structure ?
The actual issue is not how to create the menu structure, but how to add the "Cars" custom post type menu under the MyPlugin menu.
Note I have try the following option in the "register_post_type" attributes with no luck
'show_in_menu' => 'admin.php?page=myplugin.php'
Is that posible to achived ?
I had the same problem and I proved this solution:
for your plugin menu page try this:
function my_plugin_menu(){
add_menu_page(
'My Plugin',
'My Plugin',
'capabilities',
'my_plugin_index',
'my_plugin_function',
plugins_url( 'images/my_plugin_icon.png', __FILE__ ),
menu_position
);
// add some submenu pages
...
...
}
in your register_post_type
function this:
'show_in_menu' => 'my_plugin_index' // slug from your plugin menu page
this show your menu page in the position that you choose and as submenu the custom post type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With