1

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?

2 Answers 2

3

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 ;
}

The above would produce the following: enter image description here

2
  • Thanks Paul, but I already have a menu and a submenu where I need to add the sub-sub-menu option Commented Mar 16, 2017 at 5:01
  • it was just a thought. you asked @SavanDholu if there were any workarounds, and putting your menu in the toolbar was the only one I could think of. Commented Mar 16, 2017 at 14:40
1

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

1
  • Is there any work around for this ? Commented Mar 15, 2017 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.