Adding menu items to the admin bar
<li><a href=”http://www.animeonsen.com/support-us”>Support us</a></li>
<li><a href=”http://www.animeonsen.com/anime-stores”>Anime stores</a></li>
add_action( ‘bp_adminbar_menus’, ‘pages’, 15 );
That is what I did. (Sorry don’t know how to post the code as normal text!!!) It is not the best solution, but it works! Let me know if you figured out a better way.
Mod Edit// Less than angle brackets escaped – BB tags do not work .
@jedisthlm are you saing you have to create a bp-functions.php file and put it in your plugins folder? Cause I don’t see one already created anywhere.
@alanchrishughes yes create a blank bp-custom.php (not bp-functions.php) and paste on the code. Save and upload the bp-custom.php file to wp-content/plugins/ folder
@mercime thanks! I’ve been trying to figure that out for a while now. Is there a way to add a link without the drop down arrow? I don’t see any class or id added to it so I don’t know how it is picking it up.
I was looking for a way to include all navigation links in one navbar. Jens’ code snippet is brilliantly simple. Thanks!
The only drawback is you have to add links manually to get them to appear in the adminbar.
I’ve modified the code (borrowing inspiration from a snippet previously written by @david Lewis) so that:
1 – all “standard” BP Directory links appear automatically in their own dropdown;
2 – all BP plugin directories (Links, Gallery, etc) are automatically added to that dropdown;
3 – all WP pages are added automatically to the adminbar;
4 – all added WP pages respect whatever page order is set in the WP-Dashboard.
The code is here: http://pastebin.com/8FJmcgRF
To ensure that unwanted pages DON’T show up in the adminbar navigation (password-protected, Thank You pages, etc), install the Exclude Pages plugin:
Great idea! Hmm… my first REAL contribution. Cool
There’s gotta be a “How to Build a Plugin” tutorial around here somewhere…
May be this can help:
Creating a Custom BuddyPress Component
There’s got to be a much more logical way of doing this, we’re sitting here talking about adding a couple a hrefs like it’s rocket science and requires all kinds of php code. I know it takes some php to tell if a user is logged in or not and notifications, but its like the entire bar is held hostage to these few links.
The code I’ve posted is actually quite simple when you get right down to it. Simple yet powerful. It does everything you want a dropdown menu to do, and it does it all automatically behind the scenes.
It starts by identifying what links belong to dynamically generated BP directories and adds those to the adminbar in a Community dropdown. To that same dropdown, It then adds all BP directories that are created by any BP plugins you may have installed.
It then identifies all WP pages and adds them to the adminbar also. The really cool part is no matter how you’ve set up your WP page hierarchy and page order in your dashboard, that will be preserved in hierarchical dropdowns like the following example:
Parent page 1
– Child page 1
— Grand-child page 1
– Child page 2
– Child page 3…
Go ahead, give it a whirl. Copy the code to bp-custom.php and upload to your plugins folder. No need to activate anything; Buddypress will recognize and execute the code.
Take a look at my homepage: http://nowrecovery.com/
The first dropdown is all Buddypress. The ones after it are all WP. If you create an account and login, you’ll see all the adminbar goodies appear to the left and bump everything else to the right.
There is a need at present for dashboard links if one is running WP 3.0 single blog (unless one wants to have to ad the WP meta or type at address bar) I keep a function that allows me to add to adminbar links similar to that which you describe.
You may like to consider a twist or variation on your code to include the new WP 3.0 nav menus?
This example would add the ability for users to add / construct menus from the dashboard and place them on the adminbar:
It’s not checked as such and names need adjusting etc.
@pcwriter “It does everything you want a dropdown menu to do, and it does it all automatically behind the scenes.”
That’s what my problem is though, it does too much and all behind the scenes. From a design stand point, when I’m trying to figure out programs like wordpress or buddypress I try to break everything down to its most basic state so I can completely control things, so I can make a website function around an attractive user friendly design instead of limiting my design to the functionality I am stuck with because I can’t figure out what is going on hidden behind the scenes. It would be great if there was a buddypress codex with individual lines to generate single links to each page.
Can you explain further what you are after? Generate single links to pages? the menu functionality in WP 3.0 will list all pages created and allow you to create individual menus with selected pages added to them.
@hnla I mean the buddypress links. All the individual items under “My Account” and the “Notifications.” I’ve clumsily figured out how to generate a link to a logged in users account page, just by copying and pasting random bits of php from the admin bar file into my design. If there was a simple way to pull the individual links to each page that would be perfect, if there was something like…
And then I could move on from there designing whatever I wanted without worrying about the admin bar knowing that I could write
a href=” php get_myactivity_personal(); “> < img src </ a
(I don’t know how to post code on here so that is why that is written incompletely)
Anyone have any code for adding a small graphic (linked) to the admin bar? I don’t want a dropdown menu, so I’m not sure if the code mentioned on pg 1 of this thread would work for me…
@justbishop I don’t know if this will work if you are using the bp-core-adminbar.php file, but…
li class=”bp-signup no-arrow” > img src=”” </li
Thanks for the update for WP3.0! I’m still trying to find my way with basic php and am just now getting my head around functions, actions, hooks, et al.
To whit, I discovered my code is causing the Community dropdown (contains all BP links) to appear in the adminbar in member sub-blogs. The WP pages do not appear in member blogs though.
If I turn this code into a plugin (and I want to try my hand at that) I think would be good to include the option for super-admins to include/exclude BP and WP dropdowns in member blogs. I can’t figure out how to code that though. Any suggestions?
@alanchrishughes: Thanks for the reply
Is there any way you could pastebin the code? It looks like the forum may have mangled it a bit.
It is just a list item with the class “bp-signup no-arrow”. It doesn’t work pasting it directly into the bp-core-adminbar.php file, if you paste that into your header it creates a navigation bar just the same but only with the links you put in it. I’m still working on figuring out the php to generate the “My Account” and “Notification” links.
So some form of that just goes into bp-custom.php, then?
No, just paste it in your header or footer. It uses all the same classes and id’s as the original admin bar so where ever you paste this code, the style sheet will put it in the same place on all your pages.
- The topic ‘Adding menu items to the admin bar’ is closed to new replies.