{"id":638,"date":"2022-02-19T15:06:45","date_gmt":"2022-02-19T09:36:45","guid":{"rendered":"https:\/\/mutesoft.com\/spaces\/tech\/?p=638"},"modified":"2022-02-26T22:31:01","modified_gmt":"2022-02-26T17:01:01","slug":"how-to-add-a-custom-menu-to-wordpress-toolbar","status":"publish","type":"post","link":"https:\/\/mutesoft.com\/spaces\/tech\/how-to-add-a-custom-menu-to-wordpress-toolbar.html","title":{"rendered":"How To Add A Custom Menu To WordPress Toolbar?"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-1024x559.png\" alt=\"Enable toolbar for a user from edit user page\" class=\"wp-image-656\" width=\"768\" height=\"419\" srcset=\"https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-1024x559.png 1024w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-300x164.png 300w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-768x419.png 768w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-1536x838.png 1536w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-500x273.png 500w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-800x437.png 800w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2-1280x699.png 1280w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-2.png 1678w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><figcaption>Enable toolbar for a user from edit user page<\/figcaption><\/figure><\/div>\n\n\n\n<p>The toolbar includes the basic and frequently used navigation options, such as <strong>New Post<\/strong>, <strong>Edit Post<\/strong>, <strong>Comments<\/strong>, a drop-down menu for <strong>View Site<\/strong>, <strong>Edit Site<\/strong>, etc. Depending on plugins installed, you may see more options in the toolbar such as <strong>SEO<\/strong>. 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. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"48\" src=\"https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-1-1024x48.png\" alt=\"Default toolbar\" class=\"wp-image-654\" srcset=\"https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-1-1024x48.png 1024w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-1-300x14.png 300w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-1-768x36.png 768w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-1-500x23.png 500w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-1-800x37.png 800w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/image-1.png 1246w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Default toolbar<\/figcaption><\/figure><\/div>\n\n\n\n<p>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 <strong>Drafts<\/strong> filter. To simplify this, I added a new menu option named <strong>Draft<\/strong> to the toolbar. In this article, I&#8217;ll show the steps for adding custom menu options to link a page within the site or any external link.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"add-drafts-menu-to-toolbar\">Add Drafts Menu To Toolbar<\/h2>\n\n\n\n<p>Open the theme editor using the navigation <code>Themes &gt;&gt; Theme File Editor<\/code>, select the current theme from the drop-down, and open the file <code>functions.php<\/code> for editing. Add the following code block add the top of the file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function add_toolbar_items($wp_admin_bar) {\n    $wp_admin_bar->add_node( array(\n    'id'    => 'drafts',\n    'title' => 'Drafts',\n    'href'  => site_url('wp-admin\/edit.php').'?post_status=draft&amp;post_type=post',\n  ) );\n}\n\nadd_action('admin_bar_menu', 'add_toolbar_items', 40);<\/pre>\n\n\n\n<p>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 <strong>Drafts<\/strong>. You may add more such menus to the toolbar by following this process.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts-1024x39.png\" alt=\"\" class=\"wp-image-650\" width=\"1024\" height=\"39\" srcset=\"https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts-1024x39.png 1024w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts-300x11.png 300w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts-768x29.png 768w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts-500x19.png 500w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts-800x31.png 800w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts-1280x49.png 1280w, https:\/\/mutesoft.com\/spaces\/tech\/wp-content\/uploads\/sites\/4\/2022\/02\/drafts.png 1518w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Toolbar with the custom menu Drafts<\/figcaption><\/figure><\/div>\n\n\n\n<p>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 <code>functions.php<\/code> in the server would be <code>&lt;root_wordpress_folder&gt;\/wp-content\/themes\/&lt;theme_name&gt;\/functions.php<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"atomic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. \nYou will need to upload your PHP file change by some other means, such as by using SFTP.<\/pre>\n\n\n\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":2,"featured_media":656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"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.","_seopress_robots_index":"","_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[9],"tags":[13,7,25],"class_list":["post-638","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-productivity","tag-customization","tag-productivity","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/posts\/638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/comments?post=638"}],"version-history":[{"count":11,"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/posts\/638\/revisions"}],"predecessor-version":[{"id":728,"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/posts\/638\/revisions\/728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/media\/656"}],"wp:attachment":[{"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/media?parent=638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/categories?post=638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/tech\/wp-json\/wp\/v2\/tags?post=638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}