How to make menu options on tool bar like WPMU Dev?

Hi-
How would I go about creating a menu on the top bar in the admin area as you have on the WPMU Dev site?

Thank you!

Matt

  • Ash

    Hello @Matt

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    You can follow the following sample:

    add_action('admin_bar_menu', 'add_toolbar_items', 100);
    function add_toolbar_items($admin_bar){
        $admin_bar->add_menu( array(
            'id'    => 'my-item',
            'title' => 'My Item',
            'href'  => '#',
            'meta'  => array(
                'title' => __('My Item'),
            ),
        ));
        $admin_bar->add_menu( array(
            'id'    => 'my-sub-item',
            'parent' => 'my-item',
            'title' => 'My Sub Menu Item',
            'href'  => '#',
            'meta'  => array(
                'title' => __('My Sub Menu Item'),
                'target' => '_blank',
                'class' => 'my_menu_item_class'
            ),
        ));
        $admin_bar->add_menu( array(
            'id'    => 'my-second-sub-item',
            'parent' => 'my-item',
            'title' => 'My Second Sub Menu Item',
            'href'  => '#',
            'meta'  => array(
                'title' => __('My Second Sub Menu Item'),
                'target' => '_blank',
                'class' => 'my_menu_item_class'
            ),
        ));
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always.

    Hope it helps! Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.