User Avatar
How to place avatar on author's page template? (9 posts)

  1. urbanty
    Posted 4 years ago #


    I just started to play around with the User Avatar plugin, but seem to be unable to figure out, how to place it on a author's bio page. Best would be, if could place it in the author.php template file.

    Any help appreciated! :)


  2. urbanty
    Posted 4 years ago #

    Sorry for bumping, but anyone have an idea?
    Thanks! :)

  3. aboelabbas
    Posted 4 years ago #

    You can retrieve the avatar of any user by this function:

    <?php echo get_avatar( $id_or_email, $size, $default, $alt ); ?>

    For example inside the loop of author.php template to display the avatar in 60px size, the code is :

    <?php echo get_avatar(get_the_author_meta('ID'),60,'',get_the_author_meta('display_name')); ?>

  4. urbanty
    Posted 4 years ago #

    Hey Dawn, thanks for you reply. For some reason that doesn't seem to work.
    Based on your code, I modified it like this (but your original code unfortunately also didn't work):
    <?php echo get_avatar( get_the_author_meta($curauth->ID), '100' ); ?>
    Could it be a problem that I'm trying to display the avatar outside the loop?

  5. aboelabbas
    Posted 4 years ago #

    I think yes because the function get_the_author_meta('ID') shoud be used inside the loop to get the author ID , which is used in get_avatar() to get the avatar of this ID, as if u want to display the avatar of the ID 2 user the code then is :
    <?php echo get_avatar(2, '100' ); ?>

  6. urbanty
    Posted 4 years ago #

    Hm, maybe I didn't fully understand the concept of the author.php file, but it doesn't call for the loop at all. And displaying all other user meta data works fine.
    I'm using $curauth->something; and also

    <?php $user_id = $curauth->ID;
      $key = 'some_field';
      $single = true;
      $the_info_i_want = get_user_meta( $user_id, $key, $single );
      echo '<p><em>'. $the_info_i_want . '</em></p>';

    Both work just fine. Isn't the avatar also just some kind of user meta data and hence it should be possible to call it outside the loop?

  7. urbanty
    Posted 4 years ago #

    So, did actually anybody make this work with the User Avatar plugin?

    I am starting to wonder if this is maybe not possible with this plugin?
    Because when I very simply hard-code
    <?php echo get_avatar(2, '100' ); ?>
    to my author.php (user no. 2 exists and I uploaded an avatar using this plugin) the code that is being inserted to my page is the default wordpress avatar path.
    Something like
    <img alt='' src='http://myserver/wp-includes/images/blank.gif' class='avatar avatar-100 photo avatar-default' height='100' width='100' />
    So it definitely is not pointing to the path of this plugin.

    I would really appreciate help cos I'm totally stuck. :)

  8. sledge81
    Posted 4 years ago #

    My theme's default avatar code just worked. Didn't have to replace it with any of the hacks mentioned above.

    Tip: Go to settings>discussions and enable 'Show avatars' in most cases this is the culprit. Hope this helps.

  9. LexxOliver22
    Posted 4 years ago #

    Use $curauth->ID instead in the get_avatar code. So:

    <?php echo get_avatar($curauth->ID, 95, get_bloginfo('template_url').'/images/no-avatar.png'); ?>

    That finally worked for me.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • User Avatar
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic