Applying Author Gravatar In Post

Posted by Nile | Posted in Tutorials | Posted on 11-24-2009 | 2 Comments

Tags:

A few years ago, Gravatar (globally recognized avatar) was new and shiny, and people were implementing it into their blogs. Gravatar has since become easily integrable and users can simply put in their themes comment.php file:


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

Where 32 would designate the pixel size of the image that the blog owner wants to allow to be seen on their site.

However, what about those wanting to call the Gravatar to the author of a post? That can of course be done.

What yoy want to do is retrieve the blog author’s email address and get the avatar if the author has a Gravatar account. You can apply this to your index.php, single.php, archive.php where you want the author’s avatar to show on the post.


<?php
$author_email = get_the_author_email();
echo get_avatar($author_email, '32');
?>

Again, 32 is the pixel size to display the avatar. You can adjust this number to what size you wish.

You can see more documentation in the WordPress Codex about Using Gravatars. If you do not have a Gravatar account, you should really consider getting one. It is free and much better than the default mystery man that shows up in the comments if a person has no account with Gravatar.

How to Change The Default Avatar

Posted by Nile | Posted in Tutorials | Posted on 11-07-2009 | Comments Off

Tags:

Sometimes that default Gravatar with the gray and white seems boring. Lucky for you, instead of altering internal WordPres files, you can harness the power of adding a filter to your theme’s functions.php to change your default image to display.

1. Open your template’s functions.php

2. Insert the following code:

add_filter( 'avatar_defaults', 'newgravatar' );
function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/yournewgravatar.jpg';
$avatar_defaults[$myavatar] = "Your New Gravatar";
return $avatar_defaults;
}

3. Change where younewgravatar.jpg to the image you want and change the following text, Your New Gravatar to the name you wish to have your new default avatar be called.