• If users didnt assign an avatar, then there is a text shown like this:

    Avatar of “user”

    Where do i change this text output or even better, how to asign a default avatar?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I think that depends on how you set up your avatars initially to be displayed. What default avatar type are you using (WordPress, Gravatar, Monster ID, etc?

    Thread Starter wilstyler

    (@wilstyler)

    I use Gravatar, but the default Gravatar image isnt shown if a user isnt registered to Gravatar. Only the text “Avatar of USER”.
    Maybe it messes up with other plugins?
    I have Buddypress installed, besides WP User Avatar (where i set the default avatar to “Gravatar”)

    Hmm… in that case the Gravatar G logo is supposed to be displayed. Can I see the code you are using to display the avatar?

    Thread Starter wilstyler

    (@wilstyler)

    I checked the code in my WP User Avatar plugin, following code i think it is:

    // Returns true if user has Gravatar-hosted image
      function wpua_has_gravatar($id_or_email, $has_gravatar=false, $user="", $email=""){
        global $ssl;
        if(!is_object($id_or_email) && !empty($id_or_email)){
          // Find user by ID or e-mail address
          $user = is_numeric($id_or_email) ? get_user_by('id', $id_or_email) : get_user_by('email', $id_or_email);
          // Get registered user e-mail address
          $email = !empty($user) ? $user->user_email : "";
        }
        // Check if Gravatar image returns 200 (OK) or 404 (Not Found)
        if(!empty($email)){
          $hash = md5(strtolower(trim($email)));
          $gravatar = 'http'.$ssl.'://www.gravatar.com/avatar/'.$hash.'?d=404';
          $headers = @get_headers($gravatar);
          $has_gravatar = !preg_match("|200|", $headers[0]) ? false : true;
        }
        return $has_gravatar;
      }

    If you have selected Gravatar under your the WordPress settings, you only need this piece of code (since it’s pretty much built-in):

    <?php
    	# get post data
    	$temp_post = get_post($post_id);
    
    	# grab the author meta
    	$user_id = $temp_post->post_author;
    
    	# grab the email address field
    	$user_email = get_the_author_meta('user_email',$user_id);
    
    	# if you wish to display name
    	$display_name = get_the_author_meta('display_name',$user_id);
    
    	# display field
    	echo get_avatar( $user_email, $size = '150', $default = '<path_to_url>' );
    ?>

    Each time a user posts something, their avatar will be displayed… hope that answers your question.

    Thread Starter wilstyler

    (@wilstyler)

    I would like to use Gravatar as default Avatar to be shown, anywhere an avatar is set to be shown. so i dont want to show them on post or somewhere, i just want the gravatar to work properly, that means it should show the gravatar default logo if someone has no gravatar and no own avatar set.
    picture it looks like with gravatar set

    If i disable Gravatar as default Avatar in my WordPress plugin WP User Avatar, it is fine. All avatars are shown and for those who dont have an avatar selected, it is replaced by a default avatar.
    non gravatar setting

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘No Avatar – changing default text output’ is closed to new replies.