• Hi

    In my site, users can upload their own avatar from their profile. It create a user_meta called “avatar” where the url is stored.

    I’d like to display this avatar on my site, and if the user doesn’t have upload an avatar, display the gravatar.

    I try to use a filter to do it, but it doesn’t work. Here is my code. I’ve modified code found in internet

    function be_gravatar_filter($avatar, $id_or_email, $size, $default, $alt) {
    	$custom_avatar = get_the_author_meta('avatar');
    	if ($custom_avatar)
    		$return = '<img src="https://freeletics-stats.com/'.$custom_avatar.'" width="'.$size.'" height="'.$size.'" alt="'.$alt.'" />';
    	elseif ($avatar)
    		$return = $avatar;
    	else
    		$return = '<img src="'.$default.'" width="'.$size.'" height="'.$size.'" alt="'.$alt.'" />';
    
    	return $return;
    }
    add_filter('get_avatar', 'be_gravatar_filter', 10, 5);

    I don’t understand how the parametres are set. With that code, all users on comments has the same avatar : mine.

    Any ideas? Thanks

  • The topic ‘filter 'get_avatar'’ is closed to new replies.