Add Custom Shortcut Links to WordPress Toolbar

By default the toolbar shows useful links to WordPress administration 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 Single Shortcut Link to WordPress Toolbar

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

function single_toolbar_link($wp_admin_bar) {
	$args = array(
		'id' => 'designgala',
		'title' => 'Designgala', 
		'href' => 'http://designgala.com/', 
		'meta' => array(
			'class' => 'designgala', 
			'title' => 'Search Tutorials'
			)
	);
	$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'single_toolbar_link', 999);

Adding a Group Shortcut Link to WordPress Toolbar

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.

function group_toolbar_link($wp_admin_bar) {
	$args = array(
		'id' => 'social-links',
		'title' => 'Social Links', 
		'href' => 'https://www.facebook.com/', 
		'meta' => array(
			'class' => 'social-links', 
			'title' => 'Visit Social Links'
			)
	);
	$wp_admin_bar->add_node($args);
 
// Add the first child link 
 
	$args = array(
		'id' => 'facebook',
		'title' => 'Facebook', 
		'href' => 'https://www.facebook.com/',
		'parent' => 'social-links', 
		'meta' => array(
			'class' => 'facebook', 
			'title' => 'Visit Facebook'
			)
	);
	$wp_admin_bar->add_node($args);
 
// Add another child link
$args = array(
		'id' => 'google',
		'title' => 'Google', 
		'href' => 'http://google.com',
		'parent' => 'social-links', 
		'meta' => array(
			'class' => 'google', 
			'title' => 'Visit Google'
			)
	);
	$wp_admin_bar->add_node($args);
 
// Add a child link of google
 
$args = array(
		'id' => 'google-plus',
		'title' => 'Google Plus', 
		'href' => 'https://plus.google.com/‎',
		'parent' => 'google', 
		'meta' => array(
			'class' => 'google-plus', 
			'title' => 'Visit Google Plus'
			)
	);
	$wp_admin_bar->add_node($args);
 
}
 
add_action('admin_bar_menu', 'group_toolbar_link', 999);

We hope this article helped you add custom link shortcuts to WordPress toolbar on your website.

Leave a Reply

Your email address will not be published. Required fields are marked *