Home / login / Display avatar for currently logged in user with get_avatar
  • How to Display avatar for currently logged in user with get_avatar


    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.

    ( click code to copy )

    wordpress snippet : PHP

            global $current_user;
            echo get_avatar( $current_user->ID, 64 );

    ( WordPress codex functions, hooks, in this snippet. )

    get_currentuserinfo, get_avatar,
  • Thanks for the php coding….

  • Hello!

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

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

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

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

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

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

    • No problem enjoy the snippet!

      • 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

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

  • did you get my last message!?

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

  • Lakhiprasadbora

    i want ur code…pls

  • GSDFg


  • Jessica

    you saved another life thank you!

  • bapureddy

    nice, thank u so much….

  • 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?

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

  • Amit

    Hello experts,
    I was just wondering if anyone knows how to place a login user name and disply user avatar on the top menu bar as like wordpress admin bar?

    I’m using jarida theme


  • Thanks for this!

    Is there a way to have the users name also show up to the left as well?

    Would also be so cool if you did a post on how to show all three main elements for logged in users avatar, username x profile field, cover image and maybe friend/ follower number!

    Believe me i have searched high and low for posts on this and cannot find anywhere eon entire internet.


    • Hi James,
      WordPress does not have “friend/ follower number” are you using BuddyPress ?

      global $current_user;
      echo get_avatar( $current_user->ID, 64 );
      echo ‘Username: ‘ . $current_user->user_login . “n”;
      echo ‘User email: ‘ . $current_user->user_email . “n”;
      echo ‘User level: ‘ . $current_user->user_level . “n”;
      echo ‘User first name: ‘ . $current_user->user_firstname . “n”;
      echo ‘User last name: ‘ . $current_user->user_lastname . “n”;
      echo ‘User display name: ‘ . $current_user->display_name . “n”;
      echo ‘User ID: ‘ . $current_user->ID . “n”;

      The following will get all the values from the current user then you just have to write some HTML, CSS to display things the way you would like e.g.:

      user_firstname . “n”; ?>

      and so on within your template.

  • Sara Ben Chamkha

    any wordpress plugin to show name + avatar of logged in users in topbar ?

  • James

    sorry in advance for my lack of knowledge with wordpress. i placed the piece of code in my child theme (main index template – index.php) file. how would i call up or add the avatar to a sidebar widget? sorry again and thank you for your time.

  • SridharKadali

    Kevin ur GREAT lovely Thanks very much

  • SridharKadali

    Kevin ur GREAT lovely Thanks very much

    • SridharKadali

      Kevin one more thing is that even after logged-out default image is seen instead of no image is there any solution by the way iam using in navigation
      can that be made to work also as drop down menu

  • Fatih Solhan

    thank you so much, great solution!

  • GwinAgeson

    How can one Output the code in a shortcode please… I want display it in a colomn on the frontend