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.