Starting on line 474
of /wp-includes/admin-bar.php
there is a function that is declared as the following:
function wp_admin_bar_new_content_menu( $wp_admin_bar )
What it does it generates the + New
menu item along with any custom post types that a user has edit_posts
capability for. The actual top-menu item, + New
defaults to posts
since it is the first called in the array (I believe that’s how it works). I’d like to actually change that first + New
link to something else. In our setup, we need to give users edit_posts
capability to manage Advanced Custom Fields Options pages, but are not giving them access to posts themselves (which we just had to hide from the menu system). A bit funky, but it’s more of a usability concern for us.
Aside from all the jumble I said above, can you modify an existing menu link based on the ID of the item itself (which is new-content
in this case) or would I need to destroy and rebuild the menu itself? I’m just looking to change that href
attribute to #
. Thanks!
I’ve not worked with the admin-bar before. However, I found your question interesting and decided to take a look. If you add a function to handle the action hook ‘admin_bar_menu’ and set the priority to be higher than 70, you will have access to the raw admin_bar_menu nodes where you can modify the properties you are trying to access. Below is a detailed set of examples on how you can manipulate the admin-menu-bar from your theme functions.php file.
If you add this to your functions.php file, note the following changes to the admin menu bar:
Best Regards,
David Carroll
To add to David Carroll awesome answer (thanks!), I must say that to get the node name (slug name) of the existing admin bar menu and this way the possibility to alter them, you must look in the code of this new-content menu.
The
ul#wp-admin-bar-new-content-default li
have all an ID witch finishes by there name. Example:li#wp-admin-bar-new-post
orli#wp-admin-bar-new-media
wherenew-post
ornew-media
is the name you can use in theget_node()
function.For my purpose I add to change the name of the link to new Post by a custom one.