I need to add a menu to a submenu in admin menu bar. Is it possible to do this in wordpress?
For Example :
A
|
-> B
|
-> C
Or is there any work-around or hack to accomplish this?
While the main admin menus (i.e., those on the left-hand side of the screen) can only be 2 deep (A > B), nodes in the toolbar can be arbitrarily deep.
I don't know if using the toolbar would be a suitable workaround for you, but if so, then you could do something like:
add_action ('wp_before_admin_bar_render', 'wpse_admin_toolbar_test') ;
function
admin_toolbar ()
{
global $wp_admin_bar ;
$args = array (
'id' => 'wpse_admin_toolbar_test',
'title' => 'WPSE Admin Toolbar Test',
) ;
$node = $wp_admin_bar->add_node ($args) ;
for ($i = 0 ; $i < 4 ; $i++) {
$args = array (
'id' => "wpse_admin_toolbar_test_item_{$i}",
'parent' => 'wpse_admin_toolbar_test',
'title' => "Item $i",
) ;
$wp_admin_bar->add_node ($args) ;
for ($y = 0 ; $y < 3 ; $y++) {
$args = array (
'id' => "wpse_admin_toolbar_test_item_{$i}_subitem_{$y}",
'parent' => "wpse_admin_toolbar_test_item_{$i}",
'title' => "Sub Item $y",
) ;
$wp_admin_bar->add_node ($args) ;
for ($z = 0 ; $z < 2 ; $z++) {
$args = array (
'id' => "wpse_admin_toolbar_test_item_{$i}_subitem_{$y}_subitem_{$z}",
'parent' => "wpse_admin_toolbar_test_item_{$i}_subitem_{$y}",
'title' => "Sub-Sub Item $z",
// in the real-world, this URL would be to something that
// would perform the action for this node
'href' => admin_url (),
) ;
$wp_admin_bar->add_node ($args) ;
}
}
}
return ;
}
No, it is not possible to create third level menu in admin panel. If you look at the definition of add_submenu_page, you need to mention the parent slug name. For eg:
add_menu_page ( 'Test Menu', 'Test Menu', 'read', 'testmainmenu', '', '' );
add_submenu_page ( 'testmainmenu', 'Test Menu', 'Child1', 'read', 'child1', '');
The first parameter of the add_submenu_page will be parent slug name. So you may think we can write child1 as parent slug name to create the third level. Eg:
add_submenu_page ( 'child1', 'Test Menu', 'Child2', 'read', 'child2', '');
It's not working so go this Submenu reference