Simple Local Avatars
How to call the avatar in theme template? (7 posts)

  1. Xaliber
    Posted 3 years ago #

    I've installed this plugin and activated it. I've uploaded the avatar and it successfully shows in my upload folder.

    But there's one problem: how to call it from my theme? The uploaded avatar doesn't show up; what appear is only the default Mystery Man.

    I've tried get_avatar( $comment, 80 ) and <?php echo get_avatar( $id_or_email, $size = '80' ) but both don't work. :/


  2. Jake Goldman
    10up Engineer
    Plugin Author

    Posted 3 years ago #

    You're doing it right... do you have any other avatar plug-ins enabled that might be conflicting?

  3. Doodlebee
    Posted 3 years ago #

    I had the same issue too - no other plugins installed. I fixed it though. Basically, in the template file (wherever you're putting the avatar to display) you need to add this to the top of the file (or wherever, as long as it's before the get_avatar call):

    <?php global $wp_query;
          $cu = $wp_query->get_queried_object();
          $id = $cu->ID; ?>

    Which will grab the author ID of the queried author (I'm putting this in the author.php file). Then wherever you put in the avatar:

    <?php echo get_avatar( $id, $size = '120' ); ?>

    Works a treat!

  4. jesperlofgren
    Posted 3 years ago #


    When I'm adding what you write doodlebee the $id is the id of the post... Not the id of the author...

    Is this something that can vary from theme to theme?

    Best regards,

  5. Doodlebee
    Posted 3 years ago #

    Yes, that's why I indicated that I was using this code on the author.php file. The queried object on the author.php file is the author ID. If you're using it on a post, then you need to grab the author ID of the post. (if it's on a category listing page, then you have to get the author ID from within the Loop so the correct ID is passed.) There's several methods of getting the author ID.

  6. francolpm
    Posted 3 years ago #

    doodlebee your rocks! Thanks!

  7. easilyamused
    Posted 3 years ago #

    My problem was echo get_avatar( get_the_author_meta('ID'), 182 ); worked fine if the Author wrote a post, but would show the defoult if there was no published post by that Author.

    @doodlebee trick worked for me.

    Thanks a Ton ;c )

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Simple Local Avatars
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic