• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Adding an item to the “New” menu in WordPress admin bar

Discover in this tutorial how to insert an item in the “New” menu of the WordPress administration bar using code.

In previous tutorials I explained you how to customize the WordPress admin bar by adding a custom link, showing the active theme, indicate if indexing is active or even creating a custom menu.

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.

add-item-new-menu-administration-bar-WordPress
Add new plugin option in the “new” menu

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:

To see this and another 839 code snippets of this website, login or subscribe here.

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 new-content).
  • 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 admin_url( 'plugin-install.php').

Conclusions

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. 🙂

Admin area PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?