Home » BLOG » WordPress » How to add external links to Admin Toolbar in WordPress

How to add external links to Admin Toolbar in WordPress

category:  WordPress

The admin toolbar is an area that you can add any menus or external useful links that users can access quickly. I normally add the document link for my clients at the admin toolbar. So that my clients can access the document link easily. So today, I will share how to add the external links to the admin toolbar in WordPress with you.

Adding One External Link to Admin Toolbar

Simply add the source code into functions.php. It should be the functions.php in the child theme.

/** 
* On 23/10/2021 by AppleRinquest.com
* add a custom link to the admin toolbar 
*/
function ar_toolbar_link($wp_admin_bar) {
    $args = array(
        'id' => 'ar-doc',
        'title' => 'ARDocument', 
        'href' => 'https://yourdomain.com', 
        'meta' => array(
            'class' => '', 
            'title' => 'Your Link Title',
			'target' => '_blank'
            )
    );
    $wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'ar_toolbar_link', 999);

Once you save the change and refresh the WP dashboard, you will see the new ARDocument link in the admin toolbar.

See the screenshot below.

single custom link admin toolbar
Add a single external link to the admin toolbar

Learn more about the admin_bar_menu action hook.

Adding a External Links Dropdown to Admin Toolbar

Sometimes you want to add multiple external links in one group (dropdown list). Below is the source code you can add to functions.php.

/*
* add the external links to dropdown list
*/
function ar_toolbar_dropdown_link($wp_admin_bar) {
    // # Add a parent external link
    $args = array(
        'id' => 'ar-doc-group',
        'title' => 'Astra Theme', 
        'href' => 'https://wpastra.com/pro/?bsf=6909', 
        'meta' => array(
            'class' => '', 
            'title' => 'Visit Astra Theme',
            'target' => '_blank'
            )
    );
    $wp_admin_bar->add_node($args);
 
    // ## Add a first child link      
    $args = array(
        'id' => 'ar-child-node-1',
        'title' => 'Smart Slider 3', 
        'href' => 'https://nextend.sjv.io/c/2195295/976563/12535',
        'parent' => 'ar-doc-group', 
        'meta' => array(
            'class' => '', 
            'title' => 'Visit Smart Slider 3',
            'target' => '_blank'
            )
    );
    $wp_admin_bar->add_node($args);
 
    // ## Add a second child link
    $args = array(
        'id' => 'ar-child-node-2',
        'title' => 'Zakra Theme', 
        'href' => 'https://r.freemius.com/4562/4143115/https://zakratheme.com/pro/',
        'parent' => 'ar-doc-group', 
        'meta' => array(
            'class' => '', 
            'title' => 'Visit Zakra Theme',
            'target' => '_blank'
            )
    );
    $wp_admin_bar->add_node($args);
 

    // ### Add a new link under the second child link
    $args = array(
        'id' => 'ar-child-node-21',
        'title' => 'Kinsta', 
        'href' => 'https://kinsta.com/?kaid=OVBTPWJRNIMA',
        'parent' => 'ar-child-node-2', 
        'meta' => array(
            'class' => '', 
            'title' => 'Visit Kinsta WordPress Hosting',
            'target' => '_blank'
            )
    );
    $wp_admin_bar->add_node($args);


    // ### Add a second new link under the second child link
    $args = array(
        'id' => 'ar-child-node-22',
        'title' => 'SiteGround', 
        'href' => 'https://siteground.com/wordpress-hosting.htm?afimagecode=021e886945e63c3a9dbfdd10cc9c2a90',
        'parent' => 'ar-child-node-2', 
        'meta' => array(
            'class' => '', 
            'title' => 'Visit SiteGround WordPress Hosting',
            'target' => '_blank'
            )
    );
    $wp_admin_bar->add_node($args);
 
}
 
add_action('admin_bar_menu', 'ar_toolbar_dropdown_link', 999);

See the screenshot below.

dropdown custom link admin toolbar
Add the external link dropdown list to the admin toolbar

Conclusion

The admin toolbar is a very useful area for quick access by users. You can add the external links or internal links you want. Hopefully, this post is useful for you. That’s for today.