Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building Gravatar code for a theme for SEO reasons, basically don't like the default WordPress Gravatar code because for each avatar it adds an image to the page with no alt text which could have a negative SEO impact. Instead using the image as a background image with has no SEO impact.

Have the code working, but not with Mystery Man or Blank setting.

Looked at /wp-includes/pluggable.php and found the issue around line 1712 which is Mystery Man code, basically one Gravatar image is used (this image http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536) for all Mystery Men avatars except when the person has set a custom Gravatar. Similar idea with Blank.

Fixing Blank was easy enough, but what I've come up with so far means custom Gravatars (user selected ones) don't work when Mystery Man is selected. With the code below the default Mystery Man image is always used. I've looked through the WordPress Gravatar code and can't figure out how the custom Gravatars are selected?

<?php /*echo get_avatar($comment, 60);*/
$email = $comment->comment_author_email;
$size = 60;
$rating = get_option('avatar_rating');
$gravtype = get_option('avatar_default');
if ($gravtype=='mystery')
$grav_url = "http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=" . $size ."&amp;d=" . $gravtype ."&amp;r=". $rating;
elseif ($gravtype=='blank')
$grav_url = "/wp-includes/images/blank.gif";
else 
$grav_url = "http://0.gravatar.com/avatar/" . md5($email) . "?s=" . $size ."&amp;d=" . $gravtype ."&amp;r=". $rating;
?>
<div class="gravatars" style="background: url(<?php echo $grav_url ?>)"></div>

Thanks

David

UPdate : Solved

Thanks to the suggestion from Bainternet using this code below which apears to work so far (not tested extensivly yet):

<?php /*echo get_avatar($comment, 60);*/
$email = $comment->comment_author_email;
$size = 60;
$rating = get_option('avatar_rating');
$gravtype = get_option('avatar_default');
$default = urlencode( 'http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size );
if ($gravtype=='mystery')
$grav_url = 'http://www.gravatar.com/avatar/'. md5( strtolower( trim( $email ) ) ). '?s=' . $size . '&r=' . $rating . '&d=' . $default;
elseif ($gravtype=='blank')
$grav_url = "/wp-includes/images/blank.gif";
else 
$grav_url = "http://0.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?s=" . $size ."&amp;d=" . $gravtype ."&amp;r=". $rating;
?>
<div class="gravatars" style="background: url(<?php echo $grav_url ?>)"></div>

David

share|improve this question
2  
if you use get_avatar you can specify the alt (its the fourth parameter). –  Bainternet Aug 1 '11 at 7:41
    
The idea is to remove the Gravatar img src code from the search engines. The sort of image code core WordPress generates has potential SEO value (at best neutral, but possibly negative for Gravatar images), by using the image as a background image using CSS it has no SEO value either way. Removing the img src code is playing it safe SEO wise. –  David Law Aug 1 '11 at 12:39

1 Answer 1

If you look at the Gravatar API you will see that you can call a user specific and specify a default so here a built proof way to get the the image url in your code.

$email = $comment->comment_author_email;
$size = 60;
$rating = get_option('avatar_rating');
$default = urlencode( 'http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size );
$grav_url = 'http://www.gravatar.com/avatar/'. md5( strtolower( trim( $email ) ) ). '?s=' . $size . '&r=' . $rating . '&d=' . $default;
?>
<div class="gravatars" style="background: url(<?php echo $grav_url ?>)"></div>

and you have no need for conditional checks.

share|improve this answer
    
Thanks Bainternet, your code didn't work as is but helped solve the issue. –  David Law Aug 1 '11 at 12:35
    
What was the problem with the code? –  Bainternet Aug 1 '11 at 12:36
    
It worked for the Mystery Man setting, but when selecting other Gravatar types is showed the Mystery Many image. I add an if so it's only used whe Mystery Man is set and it works. Put the code I'm using in the main post above as the solution. Thanks for the code. –  David Law Aug 1 '11 at 12:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.