How To Add Shorcut Links To The WordPress Toolbar
One great thing about WordPress is its customizability. So today I’ll be featuring a nifty WordPress trick by Jeff Star of DigWP, which teaches you how to add a shortcut-link to the WordPress toolbar.
This one involves a bit of coding. In his tutorial, Star adds a link to an external page, which is his Gmail inbox, on his WP toolbar. He accomplishes this by adding the code below to the 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' => '[email protected]'
)
);
$wp_admin_bar->add_node($args);
} add_action('admin_bar_menu', 'custom_toolbar_link', 999);
If you’re planning on using this code, just make sure to remember to edit the following:
- ‘id’ => ‘gmail’ — the ID of the <li> 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’ => ‘[email protected]’ — the title attribute for the custom link
Aside from the above trick, Star also explains in his post why he chose to use Gmail as an example, and then gave additional some more resources on how to further customize the toolbar. Moreover, there he also shows how you can create a keyboard shortcut to open your links directly.
For more info, simply head over to Star’s TUTORIAL.