Can’t get current author avatar in posts

For some reason get_avatar($user_email, 125); doesn’t work. I can’t figure out why. This is my code in single.php:

<?php
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    $user_email = $curauth->user_email;
?>

  <div class="author-box clearfix">
      <img class="author" src="<?php echo get_avatar($user_email, 125); ?> " width="125" height="125" alt="<?php echo the_author_meta( 'display_name' , $author_id ); ?>" />
        <h4 class="title"><?php echo get_the_author(); ?></h4>
        <p class="title"><?php the_author_meta( 'title' ); ?></p>
        <p class="info"><strong>M: </strong><?php the_author_meta( 'user_email' ); ?></p>
        <p class="info"><strong>W: </strong><a href="<?php the_author_meta( 'user_url' ); ?>"><?php the_author_meta( 'user_url' ); ?></a></p>
  </div>

Related posts

2 comments

  1. From the get_avatar documentation, it returns the entire image element string.

    Retrieve the avatar <img> tag for a user, email address, MD5 hash, comment, or post.

    The way you’re using it, you’d want the image url, so use get_avatar_url.

    Return: (false|string) The URL of the avatar we found, or false if we couldn’t find an avatar.

Comments are closed.