How to Add a Custom Default Avatar For BuddyPress Members and Groups

A custom default avatar is something that can greatly increase the visual appeal of your BuddyPress site. I don’t have to sell you on this. When I see those ugly monster avatars littering a BuddyPress site, my first instinct is to leave the page. Aesthetics play a huge role in your site’s ability to keep users around long enough to find out what you’re about. The default avatar is also another opportunity to keep your brand consistent throughout the site.

Banish the Mystery Man, Ugly Monsters, and Trippy Patterns

How to Change the Default Avatar for Members in BuddyPress

Just add this simple little snippet to the functions.php file in your child-theme:

1
2
3
4
5
function myavatar_add_default_avatar( $url )
{
return get_stylesheet_directory_uri() .'/_inc/images/pokerchip.png';
}
add_filter( 'bp_core_mysteryman_src', 'myavatar_add_default_avatar' );

I put this together based on Travel-Junkie’s suggestion on the BuddyPress forums.

How to Change the Default Avatar for Groups in BuddyPress

Add this to the functions.php file in your child-theme:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function my_default_get_group_avatar($avatar) {
global $bp, $groups_template;

if( strpos($avatar,'group-avatars') ) {
return $avatar;
}
else {
$custom_avatar = get_stylesheet_directory_uri() .'/_inc/images/pokerchip.png';

if($bp->current_action == "")
return '<img class="avatar" alt="' . attribute_escape( $groups_template->group->name ) . '" src="'.$custom_avatar.'" width="'.BP_AVATAR_THUMB_WIDTH.'" height="'.BP_AVATAR_THUMB_HEIGHT.'" />';
else
return '<img class="avatar" alt="' . attribute_escape( $groups_template->group->name ) . '" src="'.$custom_avatar.'" width="'.BP_AVATAR_FULL_WIDTH.'" height="'.BP_AVATAR_FULL_HEIGHT.'" />';
}
}
add_filter( 'bp_get_group_avatar', 'my_default_get_group_avatar');

Credit for this code goes to BP forum moderator r-a-y. The only thing you’ll need to change here is the name of the image you’re using for the default avatar and it will automatically display.

Simple, isn’t it? Some site admins might think that leaving the monsters / mystery men would motivate your users to upload an avatar of their own. You underestimate the casual internet user. Keep your site’s design unified by changing your default avatars today.

Tags

Comments (22)

  1. thanks. i’ve been looking into creating a set of these for member to choose from. have you come across something like this when you gathered this? been gathering the right info to possibly work on a plugin to house a custom set of avatars on the change avatar settings page.

  2. Sarah, I’m actually looking for a way to edit member’s avatars from an administrative standpoint. Any way that you know of to do that for BP users?

  3. I have successfully used them.But there is a bug while using it.I don’t know whether it’s a bug or not.During the group creation process it is not showing the default avatar I have set.Its showing the Identicons but after the group creation process it is showing the default avatar set by me.Could you please help me with this as I want to show my default avatar during the group creation process also.
    Anyways thanks for this simple how to guide.

  4. Is this still working? I tried it but didn’t change anything…
    For now i replaced mysteryman in bp-core by my own image but this is not a very clean fix.. and on some pages the mystery man is defined by gravatar, so it changes back to the original mysteryman. (on the settings>discussion page for exemple)
    Also it has the problem of the size of the avatar on the “howdy USERNAME”

  5. My bad, i was uploading the wrong file -_-‘ (also i was talking about the user part, not the group)

    However, using this technique leaves me with the same issues i had (wrong size in admin bar and back to gravatar on some pages). I’ve seen that every BP install have this size issue. Is there any fix up?
    Thx.

  6. I can confirm this. I attempted to install this fix on the a child of the bp-default theme (BP 1.5.2) and it would seem that the stylesheet for the avatars for groups has changed. I know just enough to get me into trouble, but not enough to fix it. From the looks of firebug, the new theme is looking for an img.avatar tag that doesn’t seem to jive with the img tag associated with the avatars created with this snippet.

  7. The default group avatar is such an awesome idea. The code above is rather patchy in that there is no way the default group avatar can work as a thumb and it doesn’t work on the group creation process either. Any updates to getting this working more consistently for BuddyPress 1.5.x greatly appreciated.

  8. Hope anyone can help.

    im importing users into bp but i cant find a way to set the avatar for each user. i have 200 users and each has its own avatar img….

    any idea?

    thanks
    Ben

  9. Hope anyone can help.
    im importing users into bp but i cant find a way to set the avatar for each user. i have 200 users and each has its own avatar img….
    any idea?
    thanks
    Ben

  10. HI it looks like this is only good for one default avatar. Is there a way I can have a set of 12 or so avatars that are randomly added to a user profile if they don’t upload there own. Only half my users are uploading their own avatar. The same idea as how monster avatars has a set as opposed to just 1 like mystery man.
    thanks

    • ^ Thats just what I’d like to do – a set of 12 custom images.

      I also liked Giovanni’s idea of the member directory displaying the people who have uploaded their own images at the top.

      These two things would make a really great difference

  11. OK so the one thing this doesnt address is when the above is placed the small icon present in activity streams (such a x member joined y group) is not changed to the default and results in a broken image icon.

    Suggestions for fix?

  12. This has gotten much easier for groups, and it should be updated. Simply ignore all of the code for groups on here. Instead, underneath the member code at the top, add another filter below it with this line:

    add_filter( ‘bp_group_gravatar_default’, ‘myavatar_add_default_avatar’ );

    And that’s it…. you’re done!

Participate