Question

I would like to show the gravatar of the currently signed in user, and if the user has no gravatar it will show the default wp man (or img using URL)

Here is the code I have at the moment;

<div class="gravatar">
<img src="http://techyoucation.com/wp-content/themes/blank/images/treehouse.png" alt=""/> 
</div>

The code above just shows a random image that I would like to change to the signed in user's gravatar (When no users are signed in, it will hide but I will make that happen later).

So does anyone know what to I need to do in order to make it work?

Thanks in advance

Aled

UPDATE

Using

<div class="logo"><a href="http://techyoucation.com"><img src="<?php
$user_id = get_current_user_id() // Get the user ID
$size_avatar = 50 // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-    content/themes/blank/images/treehouse.png' // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar );
?>" alt="techyoucation logo" width="219" height="47" id="Logo" /></a></a>

Dreamweaver says there are 3 syntax errors? Have I used your code wrong?

Thanks

UPDATE

Okay so now I have;

<div class="gravatar">
<img src="<?php
$user_id = get_current_user_id(); // Get the user ID
$size_avatar = 50; // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-content/themes/blank/images/treehouse.png'; // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar );
?>" alt=""/> 
  </div>

but the image don't show. When I right click and select copy image URL it gives me "http://techyoucation.com/%3Cimg%20alt=''%20src='http://0.gravatar.com/avatar/?d=http://techyoucation.com/wp-content/themes/blank/images/treehouse.png&s=50'%20class='avatar%20avatar-50%20photo%20avatar-default'%20height='50'%20width='50'%20/%3E"

Any ideas.

Thanks

Was it helpful?

Solution

You just use that function, provided by wordpress pluggable functions, get avatar:

CODE UPDATED

<div class="gravatar">
<?php
$user_id = get_current_user_id(); // Get the user ID
$size_avatar = 50; // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-content/themes/blank/images/treehouse.png'; // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar ); // This prints the <img> tag with correct avatar image url
?>
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top