-1

I used this code in function.php:

wpse_49216_my_new_avatar_url function () {
     $ gender = xprofile_get_field_data ('ranking', bp_get_member_user_id ());
if ($ gender == "Top 25") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/25.png';
}
if ($ gender == "Top 24") {
return 'http://hsseek2.esy.es/wp-content/uploads/2015/04/24.png';
}
}
add_filter ('bp_core_fetch_avatar_url', 'wpse_49216_my_new_avatar_url');

function wpse_49216_filter_bp_avatar ($ html) {
     return preg_replace ('/src=".+?"/', 'src =' 'wpse_49216_my_new_avatar_url ()..' "', $ html);
}
add_filter ('bp_core_fetch_avatar', 'wpse_49216_filter_bp_avatar');

The avatar will not appear outside buddypress page, on any other page it appears. I read on the internet that I must pass the id of the User with bp_loggedin_user_id (). How do I implement this in my code?

1 Answers1

0

bp_core_fetch_avatar is a BuddyPress hook so that explains why your custom avatar is displaying on BuddyPress areas only. You will also need to filter the get_avatar WordPress hook in order for your custom avatar to display in non-BuddyPress areas.

Ref: https://codex.wordpress.org/Plugin_API/Filter_Reference/get_avatar

henrywright
  • 10,070
  • 23
  • 89
  • 150