Discover in this tutorial how to insert an item in the “New” menu of the WordPress administration bar using code.
But maybe what you are interested in is in using the “New” menu that already exists in the bar and be able to add a new element right there.
This tutorial will show you how to add the option to add a new plugin. This would be the final result.
The good thing is that you can easily customize it, let’s see how.
Snippet to insert a new item in the “New” menu of WordPress admin bar
Add the following code snippet to your functionality plugin:
In this code you use the
wp_before_admin_bar_render hook to add a new item called “Plugin” (which will direct to the add plugin page) inside the “New” menu.
This is just an example, which can be handy, but the trick is that you can modify the snippet to your liking. You just have to customize the following array arguments:
id: identifier of the menu item (required).
parent: you indicate the parent element of the menu (in this case
title: the text that will be displayed in the administration bar.
href: the link where it will go when clicked.
Tip: to modify the
href argument just visit the URL you want to be the destination and use the part after /wp-admin/. For example, the URL to add a new plugin is https://yourwebsite.com/wp-admin/plugin-install.php and so you add
Do you want to add a new item to the New menu in WordPress admin bar? Now you know how.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂