wordpress snippets last updated   : April 22, 2014
we now have 631 snippets

Display avatar for currently logged in user with get_avatar

wordpress snippet

Adding this snippet to your wordpress template will display the currently logged in users avatar in your theme. To adjust the side of the avatar change the number 64 within the get_avatar function default is 96 and max size is 512.

snippet :  PHPcopy
 <?php
        global $current_user;
        get_currentuserinfo();
        echo get_avatar( $current_user->ID, 64 );
 ?>
source →
  • http://gadgetsnewsline.com/ GadgetsNews

    Thanks for the php coding….

    • http://wpsnipp.com Kevin Chard

      No problem glad that I could help out!

  • http://www.facebook.com/people/Joj-Ala/100002337764441 Joj Ala

    Hello!

    I have a problem, when reply a comment the avatar disappers…do you know how to solve this?

    • http://wpsnipp.com Kevin Chard

      this snippet just shows the current avatar of the logged in user only. If you want to display other users avatars you need to use another method.

      • http://www.facebook.com/people/Joj-Ala/100002337764441 Joj Ala

        the avatar disappers when I try to reply a comment … the snippet not working when try to reply.

        • http://wpsnipp.com Kevin Chard

          Do you have this online so I can take a look ? use the contact form to email the link. http://wpsnipp.com/contact/

        • http://www.facebook.com/people/Joj-Ala/100002337764441 Joj Ala

          problem solved , when hit reply the avatar take the default css style

          .commentlist .avatar {
              left: 0;    position: absolute;    top: 11px;
          }

          this did the trik

          #respond .comment-icon .avatar {    left: 0;    top: 0;}thanks anyways.

  • http://www.facebook.com/profile.php?id=618145580 Tuesday Winters

    thanks so much ive been looking for a bit of code to use with the author box plugin …… thanks again!

    • http://wpsnipp.com Kevin Chard

      No problem enjoy the snippet!

      • http://www.facebook.com/profile.php?id=618145580 Tuesday Winters

        u know what … i just realised that if i log out that the avatar disappears!! :( how do i keep it inplace constantly – im currently using the snippet to display a facebook profile avatar with a about author plugin!? cheers

        • http://wpsnipp.com Kevin Chard

          This snippet shows the avatar of the logged in user so it will not display anything when your not logged in. If you can let me know what you want to do I may be able to help.

  • http://www.facebook.com/profile.php?id=618145580 Tuesday Winters

    did you get my last message!?

    • http://wpsnipp.com Kevin Chard

      I’m going to post a snippet tomorrow with the author avatar just for you. This should solve your problems.

      • http://www.facebook.com/profile.php?id=618145580 Tuesday Winters

        brillaint! – ur a star mate!

  • Lakhiprasadbora

    i want ur code…pls

  • GSDFg

    THANK YOU SOOOOO MUCH!! YOU SAVED ME !!!! :D IT REALLY HELPED!!

  • Jessica

    you saved another life thank you!

  • bapureddy

    nice, thank u so much….

  • http://www.bobodesigns.com/ Oshi Bobo

    what if i want to show it for non login user?

  • apfernand

    This might be a stupid question but where do I add this snippet?

    • http://wpsnipp.com Kevin Chard

      You should be able to place this almost anyplace in a template.

jqsnipp.com | we just launched jquery snippets website