Close Panel
 
 

16

Jul

2008

How to change default avatar in Wordpress 2.5+

By jeeremie. Posted in Wordpress

An avatar or Gravatar (Globaly Recognised Avatar) is a small image that appears next to your comment on any posts. It’s your profile picture. It will appears any time you leave a comment on a blog or forum. Here’s a screenshot of some comments taken on my site:

Avatars example

How to use Gravatar on your site

The avatar feature is by default supported in Wordpress 2.5+. Log into Wordpress and click Settings then Discussion. Scroll down to the bottom of the page to Avatar Display and select Show avatars. Click Save changes. This will turn on avatars on your site.

If you don’t have a Gravatar yet, you will need to create one here ». When you sign up to Gravatar, enter the email address you usually use to leave comments on sites and forum.

Change default avatar

If you open the default Wordpress theme and open comment.php (/wp-content/themes/default/) in a text editor you can see this line:

<?php echo get_avatar( $comment, 32 ); ?>

This code displays the gravatar of the commenter on your posts. ‘32′ is the size of your image in pixels.

If commenter didn’t sign up to Gravatar, the default avatar will be displayed. Here’s an example:

Default avatar in Wordpress 2.5.1

Now let’s see how to change the default avatar by your own image. In my case, I chose to use my logo as my default avatar (good for branding). First, create an image 32×32 and save it into your image folder (e.g. /wp-content/themes/default/images/). Now change the default code line above by this one:

<?php
    $urlHome = get_option('home');
    echo get_avatar( $comment, $size='32', $default = $urlHome . '/wp-content/themes/default/images/avatar.jpg' );
?>

The first line will get the domain name url of your site (e.g. http://yoursite.com). The second one ($default) will retrieve the avatar image from your folder image. Change the url path to your image in the line above (/wp-content/themes/default/images/avatar.jpg).

And now a full example:

<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
   <?php
       $urlHome = get_option('home');
       echo get_avatar( $comment, $size='32', $default = $urlHome . '/wp-content/themes/default/images/avatar.jpg' );
   ?>
   <cite><?php comment_author_link() ?></cite> Says:
   <?php if ($comment->comment_approved == '0') : ?>
   <em>Your comment is awaiting moderation.</em>
   <?php endif; ?>
 
   <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title="">
   <?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> 
   <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?></small>
   <?php comment_text() ?>
</li>
Style your avatar

Next step will be to style your avatar to make it look more like a photograph. Open style.css in your text editor or navigate to the dashboard and click Design then Theme Editor. Scroll down to the bottom of the page and select Stylesheet (style.css) in your right sidebar. This will open style.css in the theme editor. Find “.commentlist li .avatar” in your stylesheet. If it doesn’t exist, add the code below after “.commentlist li”:

.commentlist li .avatar {
	float: left;
	border: 1px solid #EEEEEE;
	padding: 2px;
	background: #FFFFFF;
	margin-right: 7px;
}

This will display the avatar on the left of the commenter name and add a border to it.

The end result:

custom default avatar

Done!

Avatars should be enabled on your site now. But if you run into a problem, you can check the Wordpress Gravatar documentation or leave me a comment and I will try to do my best to help you.

Technorati Tags: , , ,

Popularity: 9% [?]

 

Related posts

| Subscribe to Feed | Email the author

70 Responses to “How to change default avatar in Wordpress 2.5+”

  1. 1
    hew Says:

    Hey! Great Post! I might use this on my blog. Keep up the good work.

  2. 2
    Rob Says:

    Thanks for this just what I was looking for!

  3. 3
    Vegasmartin Says:

    Just signed up for gravat, so I want to see how this works.

  4. 4
    PinaraNet Says:

    I just know even was 2 years blogging LOL.

  5. 5
    sohbet Says:

    Thanks!

  6. 6
    Free-PHP-Scriots Says:

    Just what I was looking for!

  7. 7
    Tom Robertson Says:

    Realy informative post. Keep up the good work.
    I happened to need his info, so thank you very much.

  8. 8
    The present ideas blog Says:

    I didn’t knew about gravat I will sign up.

  9. 9
    Lots Of Freebies Says:

    I was pulling my hair out for ages trying to style that one little part but now I’ve managed with your help.

    Many Thanks.

  10. 10
    jyon Says:

    Thanks!

  11. 11
    study Says:

    excellent work

  12. 12
    Amichai Says:

    Thanks for the great post. Trying out my new Gravatar

  13. 13
    Ste Hitchen Says:

    great tip, just implemented it on my comic site. thanks a bunch!

  14. 14
    TimesLikeThese » Blog Archive » Gravatar.com Says:

    [...] a step-by-step guild on what codes to add, where to add them and what to change. I read through that page and followed all the steps and it still wasn’t working. I still had 2 boxes of avatars [...]

  15. 15
    Robert Dall Says:

    Great Article.

    It worked like a charm!

    Thanks a bunch!

  16. 16
    Earningstep Says:

    great , i love your tips

  17. 17
    tiffany and co Says:

    I greet with your points!

  18. 18
    Hosting Says:

    verry nice thnx

  19. 19
    hkdedicatedservers Says:

    great , i love your tips

  20. 20
    boyama oyunları Says:

    Thanks very nice

  21. 21
    oyUn Says:

    Just signed up for gravat, so I want to see how this works.

  22. 22
    lifeofgame Says:

    Nice!

    Thanks for the help

  23. 23
    sickmanport80 Says:

    thank you very much
    this is i’m looking for

  24. 24
    abiazka Says:

    thanks for the awesome post … this is what i’ve been looking for …

  25. 25
    abiazka Says:

    just sign up … thanks

  26. 26
    medyum Says:

    thank you very much
    nice article

  27. 27
    Jake Rocheleau Says:

    Perfect! I’ve been trying to change that stupid-looking default picture on comments in Wordpress, excellent article.

  28. 28
    The SEO Blues Says:

    In order to change your gravatar , you just need to take your Gravatar code and add the image (new)URL right after the comma:

    Default

    Changed

    Just it
    korean fashion wholesale

  29. 29
    wordpress themes Says:

    Thanks for the guide, i hope its still working on wordpress 2.8.1

  30. 30
    wow Says:

    thanks for you to share . it is so useful for us

  31. 31
    links of london Says:

    very good, thank you!

  32. 32
    cold sores Says:

    thanks.I have been upgrade 2.7 to 2.8 ,I hope it’s still useful

  33. 33
    şehirler arası evden eve Says:

    great tip, just implemented it on my comic site. thanks a bunch!

  34. 34
    medyum Says:

    thank you
    nice post

  35. 35
    ssk Says:

    Thanks for the guide, i hope its still working on wordpress 2.8.1

  36. 36
    Drew Says:

    i thought it would have just been a matter of saving over the default image… obviously not so thanks for your help, finally got it working.

  37. 37
    koxp Says:

    Thanks for this share !

  38. 38
    Zümrütevler Says:

    “Your article are very impressive. Thank you so much.”

  39. 39
    botox Says:

    Perfect! I’ve been trying to change that stupid-looking default picture on comments in Wordpress,bolgesel sayiflama.. excellent .article.

  40. 40
    cheemzy Says:

    Nice, finally found what i’ve been lookin …thanks a lot

  41. 41
    rkenshin Says:

    thanks. will try it out!

  42. 42
    4insure Says:

    I was pulling my hair out for ages trying to style that one little part but now I’ve managed with your help.

  43. 43
    OneMoreGadget Says:

    Very helpful post. Thanks for the tip. I also like the design of your site, very easy to follow. Thanks again.

  44. 44
    OneMoreGadget Says:

    Does it automatically recognize your image? Or does it only pop up if you put in the right e-mail addy?

  45. 45
    jeeremie Says:

    …only popup if you put the right email.

    In your Gravatar.com account, you can add as many email addresses as you wish and select a different image for each.

  46. 46
    haber Says:

    very nice, but my website was done with joomla :(
    thanks

  47. 47
    Shelz Says:

    Testing on my avatar. It doesn’t appear in my own blog.

  48. 48
    Digitalmalay Says:

    I tested it, and works just fine.Thank you so much.

  49. 49
    Skinfood Says:

    Very helpful post. Thanks for the tip. I also like the design of your site, very easy to follow. Thanks again.

  50. 50
    Smith Says:

    Hi
    It is the biggest secret revealed today.
    I will change my avatar right now by this method.
    Thanks

    regards !
    Smith

  51. 51
    Printable Address Labels Says:

    Perfect! I’ve been trying to change that stupid-looking default picture on comments in Wordpress,bolgesel sayiflama.. excellent .article.

  52. 52
    medyum Says:

    tnks for all

  53. 53
    car2t Says:

    Thank you for sharing. Great!

  54. 54
    medyum Says:

    Thank you very much for everything

  55. 55
    medyum Says:

    perfect blog thaks for boarding

  56. 56
    The Ska Says:

    Yah! i already tried using gravatar but i really don’t want to see my face on my post. lol

  57. 57
    Cristiane Says:

    Thanks! That is all I needed!

  58. 58
    Fahim Says:

    Just testing my gravatar on your site.. :P

  59. 59
    Mary Frank Says:

    I have an avatar for my yahoo account, how do I get the same image as gravatar ?

  60. 60
    Ryan Says:

    Thanks for this!Just what I needed.

  61. 61
    Cleansing diet Says:

    Thanks for the great post. Trying out my new Gravatar

  62. 62
    ehliyet sınav sonuçları Says:

    Yah! i already tried using gravatar but i really don’t want to see my face on my post. lol

  63. 63
    John Says:

    Hi there.
    Great Article.
    It worked like a charm!
    Thanks a bunch!

    John

  64. 64
    Daniel Says:

    Thanks for the tips. Great article for us :)

  65. 65
    Lenny Says:

    Found your blog on Ask and was so glad i did. That was a great read. I have a quick question.Is it alright if i send you an email???…

  66. 66
    Bruno Javers Says:

    Hey, nice post. I just found this blog, but I will definitely visit regularly. Keep us updated.

  67. 67
    vijay Says:

    The avatar feature is by default supported in Wordpress 2.5+. Log into Wordpress and click Settings then Discussion. Scroll down to the bottom of the page to Avatar Display and select Show avatars. Click Save changes. This will turn on avatars on your site

  68. 68
    ทํานายฝัน Says:

    Thank you very much Great post…thanks for share this.
    ………………………………

  69. 69
    İzmir Haberleri Says:

    Thanks for this useful post.

  70. 70
    mario oyunları Says:

    Just signed up for gravat, so I want to see how this works..

 

Leave a Reply

Wrap all code in <pre lang="LANGUAGE" colla="-">...</pre> and replace 'LANGUAGE' by 'html4strict' for HTML, 'php', 'javascript', 'css'...