Gravatars are Globally Recognized Avatars. They are built into WordPress’ comments by default, but there are some ways you can customize them. I’m going to outline two customizations I recently did for clients.
Note that the hooks I use here is specific to Thesis. If you’re using Genesis you should be able to replace the hooks with genesis ones ( genesis_before_post_title
instead of thesis_hook_before_headline
…). If you’re not using a framework, you can skip the functions/hooks and drop the code directly in your theme.
Displaying an author’s gravatar next to posts
If you have multiple authors on your blog, you might like to display their picture next to posts. We’ll use the WordPress function get_author()
(more information on this in the WordPress Codex).
First Function – Displays gravatar next to Features on homepage and individual post pages.
Second Function – This adds the gravatar next to the teasers (if you’re using them).
Adding your own default Gravatar
If your commenters don’t have a Gravatar, WordPress will show a default one. You can set your own default Gravatar (like your logo), by adding the following code to your functions.php file.
Maria says
Thank you so much for this! I've used the codes and tutorials from two other sites, and neither worked. Yours did! 🙂
thehopefactory says
Thanks for the tip Bill, it worked like a charm… how great is Thesis… I added it to my blog thediylab.com. Now I am just trying to customise it one step at a time… The Creative Space sounds interesting – I must dive in! Thanks again and have a great day!
Aaron says
Hello,
My company has over 200 employees, and I want to add them into the images folder. in my author.php page I have been able to link to the images by inserting
<img src="../../../blogs.dir/1/images/.jpg" alt="" title="" />
so I have tried using your code but instead of ‘/images/buildinternet-gravatar.jpg’ I have added
../../../blogs.dir/1/images/.jpg
.The problem is that it is come up with a syntax error, do you know what I am doing wrong?
Thanks,
Aaron
Aaron says
Sorry it doesn’t look like my php was picked up, so I will use(php) and (/php) for the opening and closing tags.
the link is
(php) bloginfo(‘template_directory’) (/php)../../../blogs.dir/1/images/(php) the_author_meta( ‘user_login’ )(/php).jpg
and I tried adding
../../../blogs.dir/1/images/(php) the_author_meta( ‘user_login’ )(/php).jpg to your doce after (template_directory.
Do you have any Ideas?
Bill Erickson says
I’m pretty sure you can’t use ../ in the middle of a URL. Where is the directory? I’m assuming blogs.dir is the top-level of your site. In that case you could use bloginfo(‘url’).
When you view the source of the page, what URL is rendered? How different is it from the URL you’d like?
Jeff says
You are an all star! Thank you so much for this post. All the tutorials I’ve looked at on this topic, other than yours, do not allow the user to display the author gravatar ONLY ON THE POSTS and not the rest of the pages. This was such a huge help. Thanks again man.
Lila says
I am relatively new to WordPress and am trying to get this to work. I’m using Genesis because someone said it was easier to modify than using a free theme and after struggling for days to get WordPress to do what I wanted, I was willing to shell out the money. I’m using the newest WordPress (3.5 something).
To start I tried using the First Function. I replaced the Thesis portion of the code with the Genesis code as was mentioned and went to the Custom Code editor in Genesis and added it to the Custom Function portion. When I tried refreshing the front end crashed, but luckily I was able to remove the code and everything went back to the way it was before. Can I please get a little more information?
Bill Erickson says
Make sure you leave off the