Post Pic

How to easily add shortcuts to WordPress toolbar

As with many things, WordPress makes it easy to customize the Toolbar, using the add_node() functions. In this recipe, I’m going to show you how to add a shortcut to WordPress toolbar.

Paste the code below into your functions.php file.

// add a link to the WP Toolbar
function custom_toolbar_link($wp_admin_bar) {
	$args = array(
		'id' => 'gmail',
		'title' => 'Gmail', 
		'href' => 'https://mail.google.com/mail/#inbox', 
		'meta' => array(
			'class' => 'gmail', 
			'title' => 'sales@digwp.com'
			)
	);
	$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_toolbar_link', 999);

Once done, edit the following, then save the file. You're done!
'id' => 'gmail' — the ID of the

  • element containing the custom link
    'title' => 'Gmail' — the anchor-text for the custom link
    'href' => 'https://mail.google.com/mail/#inbox' — the URL for the custom link
    'class' => 'gmail' — the class attribute for the custom link
    'title' => 'sales@test.com' — the title attribute for the custom link

    Thanks to Jeff Starr for the cool tip!

  • Leave a Comment

    * Name, Email, Comment are Required

    WP Theme of the week

    Punk rock anyone?