The admin toolbar in WordPress is a powerful way of quickly accomplishing tasks. The toolbar visibility option is customizable for each user from the edit user page. I recommend you enable this to perform tasks seamlessly and avoid endless switches between the site and admin area.

Enable toolbar for a user from edit user page
Enable toolbar for a user from edit user page

The toolbar includes the basic and frequently used navigation options, such as New Post, Edit Post, Comments, a drop-down menu for View Site, Edit Site, etc. Depending on plugins installed, you may see more options in the toolbar such as SEO. While the default options are good for most of the users, some more custom menu options to the toolbar might be helpful to be more productive.

Default toolbar
Default toolbar

For a long time, I was missing a menu option that allows me to view quickly my current drafts and start editing the most important ones. For this, I had to first go to the Dashboard, open Posts, and then apply the Drafts filter. To simplify this, I added a new menu option named Draft to the toolbar. In this article, I’ll show the steps for adding custom menu options to link a page within the site or any external link.

Add Drafts Menu To Toolbar

Open the theme editor using the navigation Themes >> Theme File Editor, select the current theme from the drop-down, and open the file functions.php for editing. Add the following code block add the top of the file.

function add_toolbar_items($wp_admin_bar) {
    $wp_admin_bar->add_node( array(
    'id'    => 'drafts',
    'title' => 'Drafts',
    'href'  => site_url('wp-admin/edit.php').'?post_status=draft&post_type=post',
  ) );

add_action('admin_bar_menu', 'add_toolbar_items', 40);

In the configuration, provide a unique identifier to the menu, add a title for display in the toolbar and add a link that will be opened when the menu is clicked. The last parameter is the priority of the menu that determines where WordPress will place the menu. Use a very high value, such as 1000, to place it at the end of the toolbar. Here is the screenshot of the toolbar with the new menu named Drafts. You may add more such menus to the toolbar by following this process.

Toolbar with the custom menu Drafts

In case you get errors like the following, while saving the file, use FTP/SFTP to transfer the updated file to the server. The path of functions.php in the server would be <root_wordpress_folder>/wp-content/themes/<theme_name>/functions.php.

Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. 
You will need to upload your PHP file change by some other means, such as by using SFTP.

Note that WordPress discourages direct modification of theme files since the theme upgrades might break your site. You may create a child theme of the current theme and proceed with the editing.

How To Add A Custom Menu To WordPress Toolbar?
Be The First

Join our list to get instant access to new articles and weekly newsletter.

Tagged on:         

Leave a Reply

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