WordPress admin bar is a very useful feature to control WordPress functions such as adding a new post or page, editing the post quickly without having to manually search for it in the backend, or clearing your cache provided by the caching plugin. With all these features, it is a useful addition to your WordPress website, which you can easily disable. Today we’re going to take a look at the possible methods to add custom links to your WordPress admin bar.
Be sure to take a backup of your functions.php file before playing around to ensure that any changes can be easily rolled back by replacing the file with the backed-up version.
Add Single Link to WordPress Toolbar
If you want to add just a single item to the toolbar, you can just copy-paste the following code into the functions.php file of your theme.
// Code to add singe link to the WordPress Toolbar
function custom_toolbar_link($wp_admin_bar) {
$args = array(
'id' => 'wpthinker',
'title' => 'WP Thinker',
'href' => 'https://wpthinker.com',
'meta' => array(
'class' => 'wpthinker',
'title' => 'WP Thinker'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_toolbar_link', 999);
Be sure to replace the id, title, href, and meta items based on your requirements.
Add Dropdown Items to WordPress Toolbar
If you want to add multiple items as a drop-down menu, you will have to use this code in your functions.php file.
/*
** Add Dropdown Custom Links to WordPress Admin Bar
*/
// Add Parent Link
function wpt_toolbar_links($wp_admin_bar) {
$args = array(
'id' => 'wpthinker',
'title' => 'WP Thinker',
'href' => 'https://wpthinker.com/',
'meta' => array(
'class' => 'wpthinker',
'title' => 'Visit WP Thinker'
)
);
$wp_admin_bar -> add_node($args);
// Add the First Custom Child Link
$args = array(
'id' => 'wpthinker-child1',
'title' => 'WP Thinker Child 1',
'href' => 'https://wpthinker.com/category/guides/',
'parent' => 'wpthinker',
'meta' => array(
'class' => 'wpthinker-guides',
'title' => 'WP Thinker Guides'
)
);
$wp_admin_bar -> add_node($args);
// Add the Second Custom Child Link
$args = array(
'id' => 'wpthinker-child2',
'title' => 'WP Thinker Child 2',
'href' => 'https://wpthinker.com/category/reviews/',
'parent' => 'wpthinker',
'meta' => array(
'class' => 'wpthinker-reviews',
'title' => 'WP Thinker Reviews'
)
);
$wp_admin_bar -> add_node($args);
}
add_action('admin_bar_menu', 'bs_toolbar_links', 999);
So that’s how you add multiple custom links to your WordPress website admin toolbar. You can add more items by copy-pasting the respective code blocks.
Tweak Admin Bar Using a Plugin
There are some plugins to customize your admin bar. Not only its look and features but can also tweak the menus listed in there. Admin Toolbar Menus is such a plugin to allow you to create custom links on your WordPress toolbar. You can easily edit the menu from your WordPress menu section.
FAQs
There is no limit to the number of links that you can add to the WordPress toolbar. However, it is not recommended to add a lot of shortcuts that might interfere with the look and feel of the toolbar. The goal of the toolbar is just to provide frequently accessed functionalities. So use it wisely.
As mentioned in this post, you can add a drop-down to the WordPress admin bar and add links as per your requirements.
If your WordPress admin bar disappeared after you made changes to it, you might have done something wrong. You can check the possible fixes in our article about the WordPress admin bar not showing.