WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Add Custom Shortcut Links to WordPress Toolbar

How to Add Custom Shortcut Links to WordPress Toolbar

Last updated on December 31st, 2013 by Editorial Staff
42 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Add Custom Shortcut Links to WordPress Toolbar

By default WordPress displays a toolbar on top of all pages to logged in users. You can take control of the WordPress admin bar, turn it off when viewing site, or even disable it for all users except administrators. However, this toolbar can be utilized in many ways, particularly if you run a busy website with multiple authors. In this article, we will show you how to add custom shortcut links to WordPress toolbar.

Why or When You Need to Add Custom Shortcut Links to WordPress Toolbar?

By default the toolbar shows useful links to WordPress adminstration screens, allowing users to quickly access different sections of their website.

However, everyone has links that they visit a lot when writing posts or working on their site. For example, links to an external resource, service, or website. These links can be added to WordPress toolbar as custom shortcut links allowing you and your users easy access to those locations directly from your site or the admin area.

Adding a Custom Shortcut Link to WordPress Toolbar

To add a custom shortcut link to the WordPress toolbar, you need to simply copy and paste the following code in your theme’s functions.php file or in a site-specific plugin.

// add a link to the WP Toolbar
function custom_toolbar_link($wp_admin_bar) {
	$args = array(
		'id' => 'wpbeginner',
		'title' => 'Search WPBeginner', 
		'href' => 'https://www.google.com:443/cse/publicurl?cx=014650714884974928014:oga60h37xim', 
		'meta' => array(
			'class' => 'wpbeginner', 
			'title' => 'Search WPBeginner Tutorials'
			)
	);
	$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_toolbar_link', 999);

This sample code adds a link to a Google Custom Search engine, which can be used to search for WordPress tutorials on WPBeginner. It uses the function add_node with the arguments described in the array. You need to replace the id, title, href, and meta items with values for your own custom link.

Adding a custom shortcut link in WordPress toolbar

How to Add a Group of Custom Links in Toolbar

We showed you how to add a custom link to the toolbar, but what if you wanted to add multiple links and create a custom menu with handful shortcuts of your own? To do that you can group multiple shortcuts under one parent item. The child nodes under the parent link will appear when a user takes the mouse on the parent link. Here is an example of how to add a group of custom links in WordPress toolbar.

/*
* add a group of links under a parent link
*/

// Add a parent shortcut link

function custom_toolbar_link($wp_admin_bar) {
	$args = array(
		'id' => 'wpbeginner',
		'title' => 'WPBeginner', 
		'href' => 'https://www.wpbeginner.com', 
		'meta' => array(
			'class' => 'wpbeginner', 
			'title' => 'Visit WPBeginner'
			)
	);
	$wp_admin_bar->add_node($args);

// Add the first child link 
	
	$args = array(
		'id' => 'wpbeginner-guides',
		'title' => 'WPBeginner Guides', 
		'href' => 'https://www.wpbeginner.com/category/beginners-guide/',
		'parent' => 'wpbeginner', 
		'meta' => array(
			'class' => 'wpbeginner-guides', 
			'title' => 'Visit WordPress Beginner Guides'
			)
	);
	$wp_admin_bar->add_node($args);

// Add another child link
$args = array(
		'id' => 'wpbeginner-tutorials',
		'title' => 'WPBeginner Tutorials', 
		'href' => 'https://www.wpbeginner.com/category/wp-tutorials/',
		'parent' => 'wpbeginner', 
		'meta' => array(
			'class' => 'wpbeginner-tutorials', 
			'title' => 'Visit WPBeginner Tutorials'
			)
	);
	$wp_admin_bar->add_node($args);

// Add a child link to the child link

$args = array(
		'id' => 'wpbeginner-themes',
		'title' => 'WPBeginner Themes', 
		'href' => 'https://www.wpbeginner.com/category/wp-themes/',
		'parent' => 'wpbeginner-tutorials', 
		'meta' => array(
			'class' => 'wpbeginner-themes', 
			'title' => 'Visit WordPress Themes Tutorials on WPBeginner'
			)
	);
	$wp_admin_bar->add_node($args);

}

add_action('admin_bar_menu', 'custom_toolbar_link', 999);

Adding a menu or group of custom links in WordPress toolbar

In this example code, first we added a custom shortcut link. Next, we added another custom link and made it a child of the first link. We added the parent link id by adding the argument 'parent' => 'wpbeginner'. Then we repeated this to add another link under the same parent link. We have also used a child link as a parent link to show you how to add sub-items to a sub-item in the your custom links menu.

We hope this article helped you add custom link shortcuts to WordPress toolbar on your website. For questions and feedback please leave a comment comment.

What would you add as a custom shortcut link in your WordPress toolbar?

42 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

16 Comments

Leave a Reply
  1. dan says:
    Jul 20, 2020 at 10:56 am

    Why this code is not work for mobile view?

    Reply
    • WPBeginner Support says:
      Jul 23, 2020 at 9:36 am

      You may want to try disabling your other plugins to ensure there isn’t a plugin that is overriding the default bar on mobile.

      Reply
  2. Tayyab Roy says:
    Apr 5, 2019 at 3:46 am

    Thanks.

    Reply
    • WPBeginner Support says:
      Apr 5, 2019 at 11:24 am

      You’re welcome :)

      Reply
  3. Mohammad Kashif says:
    Mar 11, 2018 at 3:24 pm

    Hi
    How can i add tool bar user menu in theme navigation?
    And why i don’t receive email notification when i got reply? While i select (Replies to my comments).
    Thanks

    Reply
    • WPBeginner Support says:
      Mar 11, 2018 at 7:09 pm

      Hi Kashif,

      We are not sure which toolbar user menu you want to add. Please see our guide on how to add navigation menus in WordPress may be that would help.

      Reply
  4. Court says:
    Oct 11, 2017 at 11:43 am

    This works great, my question is, how do you add a second parent menu item to this code?

    Reply
  5. Small Details says:
    Feb 28, 2016 at 9:44 am

    I don’t know if this is recommended but I was looking for a ‘new window’ solution (see Yassin’s comment). It didn’t work by itself but works fine when combined with ‘meta’:

    add_action( ‘admin_bar_menu’, ‘toolbar_link_to_mypage’, 999 );

    function toolbar_link_to_mypage( $wp_admin_bar ) {
    $args = array(
    ‘id’ => ‘my_page’,
    ‘title’ => ‘PRODUCT MANAGEMENT’,
    ‘href’ => ‘http://www.mexample.com’,
    ‘meta’ => array( ‘class’ => ‘my-toolbar-page’, ‘target’ => ‘_blank’ )
    );
    $wp_admin_bar->add_node( $args );
    }

    Reply
  6. Mel says:
    Nov 20, 2015 at 9:52 am

    Thanks!! This helped me out a ton!

    Reply
  7. Frederic says:
    Oct 22, 2015 at 10:22 pm

    Thanks! Very useful!

    Reply
  8. Yassin says:
    Jul 10, 2015 at 7:31 am

    Great tip
    How can we make these custom links open in new tab ?
    I try to add ‘target’ => ‘_blank’ but didn’t work

    Reply
    • Henry E. says:
      Sep 14, 2016 at 12:06 am

      To add a ‘target’ => ‘_blank’ you have to add it to the ‘meta’ => array()

      Reply
  9. Gary Cook says:
    Jun 14, 2015 at 12:00 am

    This is awesome. Thanks. Although, I have added several custom menus and I want to center them all in a group using CSS, if possible? Please.

    Reply
  10. Marc says:
    Dec 25, 2014 at 7:02 pm

    Is it possible to add a icon?

    Reply
  11. Rosendo Cuyasen says:
    Feb 26, 2014 at 11:36 pm

    Cool! I think this is a cool feature for WordPress if you’re going to use this toolbar above your web pages. Thanks for sharing.

    Reply
  12. adolf witzeling says:
    Jan 16, 2014 at 5:16 pm

    I was looking for something like this. Thanks for sharing this awesome tip.

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
Smash Balloon
Smash Balloon
Add Custom Social Media Feeds in WordPress. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2021 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2021)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2021)
    • SiteGround Reviews from 4464 Users & Our Experts (2021)
    • Bluehost Review from Real Users + Performance Stats (2021)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2021 – Step by Step Guide
Deals & Coupons (view all)
SendinBlue Coupon Code
Sendinblue Coupon
Get Sendinblue, a powerful marketing automation toolkit for small businesses, for FREE.
InMotion Hosting
InMotion Hosting Coupon
Get an exclusive 50% off InMotion hosting plus a free domain.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
  • Growth Fund
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon
  • AIOSEO

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress Security by Sucuri.