How to Add Links to the WordPress Admin Bar / Toolbar

How to Add Links to the WordPress Admin Bar / Toolbar


If you’d like to add links to your Admin Toolbar (formerly called the Admin Bar), then there are two ways you can go about that: You can use a plugin, or you can use code in your functions file. We’ll go over both ways below.

1. Plugin – Custom Admin Bar

Of course we need look no further than WPMU DEV’s own Custom Admin Bar plugin to do the trick of adding links to our Admin Toolbar.

This is a FREE plugin, but like all plugins from WPMU DEV, it sees regular updates to insure compatibility with the latest versions of WordPress.

The Custom Admin Bar plugin lets you …

  • Create dropdown menus
  • Use and image for a top menu item
  • Easily link to internal or external pages
  • Drag and drop menu items to sort them
  • Create a menu “hub” item that doesn’t link anyway but has sub-menu items that do

 

Here’s a look at adding a link.

First choose the type of link it is:

  • Link to an internal admin page
  • Link to internal Post or Page
  • Link to external site

 

Then add the name for the menu item and link for the page.

 

And here’s a look at the result.

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

Here’s a short video of the process to show you how quick and easy it is.

xKrOCd9bnSY

 

 

 

2. Code in Functions File

If you’d like, you can also add new links to your Admin Toolbar by inserting code into your functions.php file. (Appearance > Editor > Theme Functions – functions.php) This doesn’t offer all the options the Custom Admin Bar plugin does, but it will add your links for you.

You will just need to fill in the code with your own information in various places where required.

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'
        ),
    ));
}

 

Thanks to wp-snippets for this code.

Photo: Chain Link Close Up from BigStock

Tags: