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

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:

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.

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

How to Change the Default Avatar for Groups in BuddyPress

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

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" src="'.$custom_avatar.'" alt="' . attribute_escape( $groups_template->group->name ) . '" width="'.BP_AVATAR_THUMB_WIDTH.'" height="'.BP_AVATAR_THUMB_HEIGHT.'" />';
else
return '<img class="avatar" src="'.$custom_avatar.'" alt="' . attribute_escape( $groups_template->group->name ) . '" 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: