Support » Plugin: Simple Local Avatars » [Plugin: Simple Local Avatars] How to call the avatar in theme template?

  • 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. :/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jake Goldman


    10up Engineer

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

    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!


    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,

    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.

    doodlebee your rocks! Thanks!

    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 )

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Simple Local Avatars] How to call the avatar in theme template?’ is closed to new replies.