BuddyPress
How to customize BuddyPress admin bar
On 23, Mar 2011 | 40 Comments | In | By Mike
When I re-designed AvenueK9.com, I didn’t want to have the default BuddyPress admin bar displayed like the one below.
And when WordPress 3.1 shipped out with the its own admin bar (below), I didn’t want that either!
Both are very useful, but when your only focus is to design something that doesn’t look so out-of-the-box, in terms of BuddyPress and/or WordPress designs, you’ll inevitably find yourself writing writing some custom code snippets. In my case, to de-clutter all whatever-bars, I started from scratch and hard-coded my own navigation. The neat thing is, since my current Avenue K9 BuddyPress theme is a child theme off of the Default BP theme, WP and BP upgrades are still a breeze. I don’t anticipate the actual navigation items changing either, so these following set of mods have worked out for me thus far.
Before I dive straight into the what and how, let me just say this: The following is not an official guide for how to customize the BuddyPress Admin Bar much like my previous how-to BuddyPress post. In fact, I scoured the BP forums on how to do exactly this, so if the php code isn’t quite kosher, feel free to only use whatever information you feel applies to you.
Let’s start. Here’s a picture of what we’re about to do…
As you can see, I’m also running Paul Gibbs’ Achievement plugin on my dog site, so you can see how an unlocked Achievement notice would look like in action.
Step 1: De-cluttering the WP/BP bars
To remove the default BuddyPress Admin bar, open up your wp-config.php file and add this line near the Multi-Site lines..
define ( 'BP_DISABLE_ADMIN_BAR', true );
To remove the WordPress 3.1 admin bar, add the following line to your functions.php file…
<?php add_filter( 'show_admin_bar', '__return_false' ) ?>
If your theme does not have a functions.php file, launch Notepad, create a file called functions.txt, upload it to your server, change the extension from .txt to .php and copy/paste the line above.
Step 2: Create a new BuddyPress function to initialize your custom BP admin menu
Create a new php file labeled bp-functions.php and upload it into your theme folder; this is in addition to your functions.php file — they are two separate files.
Next, copy/paste the code below into the bp-functions.php file:
< ?php function my_bp_adminbar_notifications_menu() {
global $bp;
if ( !is_user_logged_in() )
return false;
echo '
- loggedin_user->domain . ‘”>’; _e( ‘Notifications’, ‘buddypress’ ); if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?> < ?php } echo ‘‘; echo ‘
- ‘; if ( $notifications ) { ?> < ?php for ( $i = 0; $i <li >
- <a href=”loggedin_user->domain ?>”>
< ?php } echo ' '; echo ''; } ?>
Step 3: Add custom BP admin navigation items to your theme
This step will most likely take place in your theme’s header.php file, unless you’ve got some seriously tricked-out version of your theme. For the AvenueK9.com site, I used the following code:
'; } ?>
- <a href=”settings/”>Settings
- <a id=”logout” href=”">
Notice that the line below (second nav item from the top) links to the directory for the Achievements plugin. You do not need this line, if you don’t want to display it or if you’re not running the plugin on your site.
<li><a href="<?php echo bp_loggedin_user_domain() ?>achievements/">My Achievements</a></li>
Step 4: Applying CSS to your Custom BP admin navigation
This step is all up to you and how you want to display your nav items. I decided to stick with the multi-dropdown navigation but you could as easily also display it as a horizontal bar (like an older version of the official BuddyPress.org site had it, if you were lucky enough to see it!). There are a thousand different ways to style this, so suffice to say that I won’t go over this step in detail. Just style away!
Step 5: Hiding custom BP admin navigation for logged out users (optional)
If you even want to go a step further with your BP mods, you can do the same thing I did at my dog site — hiding the buddypress admin menu for logged out users like so…
This actually serves two purposes: Not only will logged out users not see a bunch of useless nav items (they won’t work if you’re not registered), but replacing “My Account” with “Become a K9ner” actually utilizes this space to register new users. Obviously, the call to action could be something completely different and doesn’t even need to point to your registration page, but if you’ve already dedicated some real estate to the BP admin menu, you might as well use it efficiently.
Here’s how:
I’ve actually created a new nav item and placed it above the custom BP admin code like so (bold)…
<ul id="signup"> <li><a href="http://avenuek9.com/signup/">Become a K9ner</a></li> </ul> <ul id="navk9"> <li><a href="#">My K9 Account</a> <ul>
Since the Default BP theme ships with body classes, I can control which navigation is displayed or hidden using the body class .logged-in like so…
body.logged-in ul#signup{display: none}
body.logged-in ul#navk9{display: block}
So if you’re logged in, this css will hide the Become a K9ner link and display the customized My Account nav instead.
That’s it!
If you’ve previously customized your navigation menus on your BP site, you can easily copy over all your css rules and apply them to your newly-created admin navigation. Cheers!
-
thanks,
It’s good….. -
Thanks a lot for this!
-
I’ll try it. Thanks a lot!
-
This is great, thanks. There are some spacing issues in your “< ?php" but after I fixed that, everything was great!
-
Thank you for writing this tutorial! Your current code is pretty crazy though… I don’t know if it is supposed to be formatted the way it is. Is there a way that you can post the code on pastebin or something so it is formatted nicely? On multiple browsers your code just gets pretty jumbled. I’m not sure what is correct and what isn’t.
Otherwise it looks great!
-
No problem. Here’s Step 2 – http://pastebin.com/YEas6HFZ
and Step 3 – http://pastebin.com/ZGXvEsxg … hope this helps =)
-
-
I can’t get step 3 to work… It complains about unexpected T_OBJECT_OPERATOR, expecting ‘,’ or ‘;’ here: return false;
echo ‘loggedin_user->domain . ‘”>’; _e( ‘Notifications’, ‘buddypress’ ); if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?> <?php } echo ‘‘; echo ‘but I don't know what… I have fixed all the spacing in the <?php.. Can you help me please?
-
OMFG I have been looking for this for like 2 months now LOL. Thank you so much! To me, The WP/BP bar takes up too much space (I’m on a netbook), and it looks better when these are integrated into the theme/WP Menu navigation more. Thanks!
-
Thanks dude!! It works perfectly!
-
I’m trying to put the notifications in a new sub nav, but I can’t get it to work. This is what I have: http://pastebin.com/jJgjyZCW
-
Thanks for the notifications code ( Step 3 )

Saved me a few hours of searching – had to change it up slightly being used in a custom build admin bar inheriting the wp default admin bar styles. -
Great tutorial, thanks! However, one minor issue.
Due to the nature of my menu, i cant apply these to UL, and they need to be applied to LI only (it’s one full menu, with only one UL wrapped around it).
body.logged-in ul #signup{display: none;}
body.logged-in ul #navk9{display: block;}removing UL from them did work for #signup, but not for #navk9.
The following is what I have now, and it works for #signup.body.logged-in #signup{display: none;}
body.logged-in #navk9{display: block;}Changing the #navk9 to either of these does nothing either:
body.logged-in li #navk9{display: block;}
body.logged-in ul li #navk9{display: block;}The register link disappears when I log out. However the account menu doesn’t.
Any clues? Much thanks!
-
I managed to get around this by using php to include it, rather than CSS to hide the menu item.
I cut the code for the My Account menu and put it into a seperate file called adminmenu.php (saved in my theme), then added the following code to the menu in it’s place. This way if a user is logged in, they get the My Account menu. If they’re not, nothing appears.
Just in case anyone’s having the same problem as me, this may be another solution.
-
That was supposed to show
if ( is_user_logged_in() ) {
include ‘adminmenu.php’;
} else {
echo ”;
};within php tags.
-
-
-
I’ve been looking all over for a tutorial to replace the admin bar for logged in users with a custom, small drop down menu like this one. Unfortunately, I cannot get this to work.
I did see the pastebin links for step 2 and 3. I did exactly as instructed and do see the items, but it is not a drop down menu, it just shows the items line by line.
Step 4 mentioned you stuck with the multi-dropdown navigation, that means that it already should have a dropdown navigation as is, correct? Or is there some additional coding involved that I am missing?
Appreciate any help, thank you. I’m running the latest WP/BP stable install.
-
Hi Mike,
Thanks for your tutorial! I´ve followed step 1-4, but am experiencing problems now with the menu I´ve created ad the urls are not working
I also want to add the sublevels, but have no idea where to find the urls for these (as my admin bar is deleted I can´t go to these parts of my site)
Would you mind if I send you an email with more details?
-
I’m not using this for BP, but do you know where the WP menu is in the P2 theme?
-
I’m getting this error Call to undefined function bp_dtheme_page_on_front()
-
I received the same error. I have have turned off every plugin except Buddypress and WPML. the error remains. *note I have placed step 3 script into my member-header.php
When I placed the script into the header.php nothing happened. At least now I see the links, followed by the error.
Fatal error: Call to undefined function bp_dtheme_page_on_front() in /mnt/44444/domains/ccarts.ca/html/wp-content/themes/child-CCA/members/single/member-header.php on line 79
I have tried removing all other functions one by one but then the site doesn’t run at all. (the page is blank)
-
-
I think the code is not formatted properly. Can you format the code with or something? I don’t understand the code…
Thanks -
Hi Mike,
Thanks for sharing this tutorial. -
Thanks for this. Exactly what I needed.
-
thanks!
-
Oh man, I’ve been looking for this solution for ages! Thanks, works like a charm!
Submit a Comment















Comments