Changing Buddypress default logo with a custom logo in buddypress admin bar

Jotted by brajesh on July 26, 2009

Do you use buddypress? If you use buddypress, you might have seen the buddypress admin bar.

here is a small screenshot for reference.

buddypress admin bar

As expected,most of  the time you will like to brand your site and will be using your custom theme for your buddypres powered site.

and here is what do I mean by buddypress admin bar logo
buddypress admin bar logo

How do you change the byddypress logo in the buddypress admin bar? do you edit the  bp-core/bp-core-adminbar.php or upload image to bp-core/images direcotry.These are not recommended as It will wipe out your customization with the next upgrade of buddypress.

Well,So here Is an easier way , you can use to add your own logo and custom alt text for the logo in the buddypress admin bar.

Buddypress provides two hooks for the purpose

bp_admin_bar_logo_src and bp_admin_bar_logo_alt_text .You cn use these filters to easily specify your logo/alt text without tempering with the core file.

Now let me show you an example how to do it

First of all ,we need to add the filters

<?php
/*Let us add the filters */
add_filter("bp_admin_bar_logo_src","cc_my_adminbar_logo");//it will help us modify the logo image
add_filter("bp_admin_bar_logo_alt_text","cc_my_adminbar_logo_alt_text");
//allows you to change the alt text specified for your site
 
?>

As you may see,we have just added the two filters, now we need to define the two functions cc_my_adminbar_logocc_my_adminbar_logo_alt_text.
These function names can be anything, just make sure you use the same name in function definition ,which you used in the “apply_filters

The function “cc_my_adminbar_logo” returns the absolute url of the image you want to use in place of buddypress default logo. and the function “cc_my_adminbar_logo_alt_text” will return the alt text we want to be used with the admin bar logo.By default it is “buddypress”.
So ,let us complete our code.

<?php
/*Let us add the filters */
add_filter("bp_admin_bar_logo_src","cc_my_adminbar_logo");//it will help us modify the logo image
add_filter("bp_admin_bar_logo_alt_text","cc_my_adminbar_logo_alt_text");
//allows you to change the alt text specified for your site
 
 
 
/*
* cc_my_adminbar_logo($default_logo_src) returns the absolute url of your custom image
*/
function  cc_my_adminbar_logo($default_logo_src)
{
/*let us ignore the defult buddypress logo url,which is passed as the first arguement*/
$my_logo_url="http://example.com/custom-adminbar-logo.png";
/*change the value of $my_logo_url with your own custom logo;
*/
return $my_logo_url;
}
 
/**
*cc_my_adminbar_logo_alt_text($defult_alt_text) 
* returns the custom alt text from admin bar logo
*/ 
function cc_my_adminbar_logo_alt_text($defult_alt_text)
{
/*ignore the default text*/
 
$my_logo_alt_text="MyWonderFulSite description";
/*Please change the $my_logo_alt_text value with your own custom value
*/
 
return $my_logo_alt_text;
}
?>

That’s it, we return our own admin bar logo url and the alt text.

To use it on your site, modify the above code with your custom requirement(logo url and text).Put it in some php file and upload it to wp-content/mu-plugins directory,go and visit your site.The logo will be changed.

Though,It’s simple,I hope it helps.Let me know ,how it goes with you.

Note: There was a typing mistake in the original article as pointed by Eduardo,now it is corrected.Thanks Eduardo for pointing.

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]
If you enjoyed this post, make sure you subscribe to my RSS feed!
Grab my other free plugins here at wordpress Plugins repository.
We will keep coming with more informative tips,tricks,tutorials to keep you updated with wordpress/buddypress/wordpress mu regularly.If you want to help us,You can ,by spreading the words.We provide free and premium plugins/support for wordpress Mu,buddypress at a very low cost (starting with $30 for 3 months membership).If you or anyone you know,needs some real good plugins/themes for their wordpress Mu/buddypress powered site, Please refer them to http://BuddyDev.com.We will highly appreciate your support and keep coming with more useful and free stuffs.

Related posts:

  1. Turn Your buddypress website to orkut style Site Now:Grab Cosmic buddy Theme for buddypress We have just released the Cosmic buddy Theme for buddypress....
  2. Adding Sitewide Menu Items to a buddypress site In this post,I will show you the quickest way to...

Related posts brought to you by Yet Another Related Posts Plugin.



9 Responses to “Changing Buddypress default logo with a custom logo in buddypress admin bar”

  1. Eduardo says:

    Thanks. I was looking for a way to modify the logo without digging through or changing any of the original code and new this was possible with hooks so thanks for this wonderful reference. I should mention that the above mentioned apply_filter(“bp_admin_bar_logo_src”,”cc_my_adminbar_logo”); did not work for me and I think it’s wrong. I used add_filter(“bp_admin_bar_logo_src”,”cc_my_adminbar_logo”); instead and that worked just fine.

  2. Chia says:

    Once again I end up on our site and find the solution I need. Thanks a bunch!

  3. Chia says:

    Ugh…I spoke too soon. I got a big fat error on line 6. Being a PHP noob I couldn’t figure out how to fix it. Argh! Thus, I still have “buddypress” in my admin bar.

    • brajesh says:

      Hi
      Thanks for your comments.
      I am sorry,there were small typos,Please check the updated code above,just copy paste and change appropriately.It will work.
      If you find any issues,please let me know.

      Thanks
      Brajesh

  4. Law says:

    Awesome this works! thanks!

    I tried overwriting the default image “bp-core/images/admin_bar_logo.gif” but that caused it to be pixelated… but this works great thanks again!

  5. Jack says:

    Hi,

    Can someone please explain when should I use apply_filter instead of add_filter?

    Is it used when I want to call an existing filter without typing the hook again?

  6. Dee says:

    I have a couple questions:

    One, Do we simply create a .php file, insert the above mentioned code, and put that file in wp-content/mu-plugins directory? Or do we need to insert the filters in a particular file, too?

    Two, is this compatible with the newest version of BP?

    BONUS!!! If someone could lay this out in a “Changing BP Logos for Idiots” format, that would be great! I’ve never worked .php and have done very little .css. One can’t assume that I know anything. ;)

    • brajesh says:

      hi Dee
      I guess,this will not work with buddypress 1.1(or above) as there has been some code modifications in the admin bar and there is no logo,instead ,the site name as a link is used in place of logo.
      Still,there exists a way to add your own long(in case you wish so).just we need to work on the action hook “bp_adminbar_logo”
      here I have posted a code snippet for clarification ,how to do it in the new system.
      http://cosmiccoders.pastebin.com/f15deabca

      The best thing is you can put it now simply in the functions.php file of your active theme and it will work.
      Or create a new php file and put it into the mu-plugins both will work.

      Hope it helps.


Leave a Reply


Get Adobe Flash playerPlugin by wpburn.com wordpress themes