How to create child child admin menu page

[ad_1]

Hey guys!

I’m creating a plugin with custom pages on wp-admin side. I have the main level page, which is actually just the menu and then child pages, which opens different pages.

So far it’s working as expected. I can load the data I need and display it on the page as expected. This is my code so far:

add_action(‘admin_menu’, function() {
$icon = ‘<svg>…</svg>’;

  add_menu_page(‘Financial’, ‘Financial’, ‘manage_options’, ‘myplugin-finance’, ‘render_page_base’, ‘data:image/svg+xml;base64,’.base64_encode($icon));

// Add child pages
  add_submenu_page(‘myplugin-finance’, ‘Overview’, ‘Overview’, ‘manage_options’, ‘overview’, ‘render_page_overview’);
  add_submenu_page(‘myplugin-finance’, ‘Transactions’, ‘Transactions’, ‘manage_options’, ‘transactions’, ‘render_page_transactions’);
  add_submenu_page(‘myplugin-finance’, ‘Customers’, ‘Customers’, ‘manage_options’, ‘customers’, ‘render_page_customers’);
  add_submenu_page(‘myplugin-finance’, ‘Transfers’, ‘Transfers’, ‘manage_options’, ‘transfers’, ‘render_page_transfers’);

// Remove parent from child menu list
  remove_submenu_page(‘myplugin-finance’,’myplugin-finance’);
});

I tried to create the page details like this:

add_submenu_page(‘transactions’, ‘Transaction details’, ‘Transaction details’, ‘manage_options’, ‘transactions-details’, ‘render_page_transactions_details’);

I can open this page, but the menu isn’t opened and/or selected on the correct menu item. Is there a way to achieve this? Woocommerce product does what I want to do. If you select the list of products, the Woocommerce menu stay opened with Products selected. If you then select one product to edit its details, the menu stays the same. Forminator is also another plugin I use that does this, but I was not able to identify how they do that.

This is my desired result:

&#x200B;

https://preview.redd.it/12zfpnomv9yc1.png?width=686&format=png&auto=webp&s=243f0db08b877e27d09f04fcb25d953cf2a2cc70

[ad_2]
2 Comments
  1. You access the submenu page and it doesn’t activate the submenu item like in your screenshot?

    Is that what you are asking?

  2. WordPress won’t allow a second level of submenus so it won’t work the way you are attempting.

    [More info](https://wordpress.stackexchange.com/questions/226990/how-to-add-a-third-level-sub-menu-to-the-wordpress-admin-menu) and potential work around if you must have it.

    The woocommerce example you’ve shown for products is a post type that can have its own hierarchy which is a different scenario. You can create your own for transactions and that will work the same.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer