Jump to content

PHP Gravatar code


weedshop

Recommended Posts

Hello all! I use wordpress for blogging and on this site i am trying to display users gravatars on the site. If users have not set a gravatar, then i would like it to show the "default" image it shows now. I am also looking to display the users name, nickname and a edit my profile link for the logged in users. Here is the code i have now but it will always show my gravatar:

 

<h2><?php _e('Your Gravatar'); ?></h2>

<?php global $userdata; get_currentuserinfo();

echo($userdata->first_name);

echo " ";

echo($userdata->last_name); ?>

<?php global $user_email;

get_currentuserinfo();

echo "<img src='";

echo gravatar($user_email);

echo "' alt='' class='gravatar' width='60' height='60' ALIGN=LEFT />";

?>

Nickname:

<?php global $userdata; get_currentuserinfo(); echo($userdata->user_login); ?>
<?php global $user_email;

 

 

Ooppss, here is a link to my site: https://www.weedshopinc.com  and on the left side of the page you will see "your gravatar". Thanks for any help

Link to comment
Share on other sites

There's no context around the code you've posted, but there appear to be a couple issues. First and foremost, you're using get_currentuserinfo() , which is deprecated in favor of wp_get_current_user(). Even beyond that, you're requesting the data of the currently logged in user, which is you. So actually your code is doing exactly what you've asked it to do. Another issue is that you're calling get_currentuserinfo() multiple times - if all this code is in the same template you don't need to do that.

Give some context to what you're trying to do with this code. If you're in the WordPress loop, use the information about the current post.

Edited by maxxd
typo
  • Great Answer 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.