Setting default Avatars for your Groups and Member pages

Most people are not big fans of the default Gravatars BuddyPress uses. That’s why you might want to use your own default images for new Members and Groups. This snippet was inspired by a post by Sarah Gooding on WPMU.org (which snippet did not work for me) and some help from Jeff Sayre through Twitter. The

Put the following code in functions.php or bp-custom.php:

/* Default Avatars */
function bn_new_mysteryman () {
        return get_stylesheet_directory_uri() . '/_inc/images/no_photo.jpg';
}
add_filter('bp_core_mysteryman_src','bn_new_mysteryman',2,7 );
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/no_photo.jpg';
if($bp->current_action == "")
return '' . attribute_escape( $groups_template->group->name ) . '';
else
return '' . attribute_escape( $groups_template->group->name ) . '';
}
}
add_filter( 'bp_get_group_avatar', 'my_default_get_group_avatar');

Put the default images you want to use in your themes folder _inc/images/ directory and you’re done. If you need a default image, you can use this one for groups:

no photo Setting default Avatars for your Groups and Member pages

And this one for Members:

nophoto Setting default Avatars for your Groups and Member pages

BuddyPress Hosting Guide Looking for quality BuddyPress hosting? We will guide you through all the available hosting options and help you find the best webhost for your next BuddyPress project!

Something about bowe

BuddyPress fanatic, WordPress Theme designer and MultiSite community builder. Proud co-founder of PressCrew. Loves to use awesome in every sentence. Often described as a Dutch Treehugging Hippie.

8 Responses to Setting default Avatars for your Groups and Member pages

  1. momo December 2, 2010 at 11:58 pm #

    Hello,

    can u share the psd of the too picture?

    nice tricks!

    Reply
    • bowe December 4, 2010 at 1:02 pm #

      Sure.. I’ll upload them and update the post :)

      Reply
  2. Daniel December 4, 2010 at 10:22 am #

    I have tried these out on a number of sites and the change to the dafault members avatar is fine, but I have had problams as others have with the default group avatar. You can see my recent link as to what the problem is…and our plugin to solve the problem

    Reply
  3. bowe December 4, 2010 at 1:06 pm #

    Hi Daniel,

    Cool you’ve made a plugin for it! Also like the fact that you can upload an image and do not have to use functions.php or bp-custom.php. Well done :)

    Reply
  4. leticiachenry April 10, 2012 at 6:03 pm #

    nice hack :)
    any idea why site.com/members/me/groups/ may display custom avatars at 50px X 50px and default once at 150px X 150px ?

    Reply
  5. Hope January 17, 2013 at 1:37 pm #

    Hi Bowe,

    Thanks for this code… I tried it but for default user avatar, it didn’t work! What could the problem be?

    Reply
  6. Marvel Slots June 17, 2013 at 10:05 pm #

    thanks for the great snippet, worked like a charm. It makes the pages load much faster too as the theme is not searching for external avatars via gravatar

    Reply
  7. jakobol July 18, 2013 at 11:38 pm #

    then i put that code in the fuction.php i get this error > Parse error: syntax error, unexpected T_STRING in…….

    Reply

Leave a Reply