How well are you using avatar in your wordpress blog? Let see how people spice up avatar section in their wordpress. This entry provides us 10 most useful code snippets and wordpress plugins that help us control, customize our avatar in wordpress better.
Like the article? Be sure to subscribe to our RSS feed and follow us on Twitter to stay up on recent content.
Change the Default Gravatar in WordPress
add_filter( 'avatar_defaults', 'newgravatar' ); function newgravatar ($avatar_defaults) { $myavatar = get_bloginfo('template_directory') . '/images/buildinternet-gravatar.jpg'; $avatar_defaults[$myavatar] = "Build Internet"; return $avatar_defaults; }
By default, if users don’t have gravatar with their email, wordpress gives you an option that can be change the default avatar in Setting>Discussion. However, you can replace or add one more option that default avatar can be replace by your own image.
Source: Build Internet
Using Twitter avatars in comments without plug-ins
First, grab the functions file here.
Then, copy all the content of twittar.php and paste it to your functions.php file
Finally, copy and paste code line below to your comments.php file within the comment loop.
<?php twittar('45', 'default.png', '#e9e9e9', 'twitavatars', 1, 'G'); ?>
Automatically insert author bio on each post
Using WordPress hooks, it can be very easy to modify WordPress variables to fit your needs. In this recipe, I’m going to show you how to use hooks to automatically insert the author bio after each post.
Open your functions.php file and paste the following code. After insert these code, you can customize the css for the author bio box easily.
function get_author_bio ($content=''){ if(!in_category("Community News")) { $post_author_name=get_the_author_meta("display_name"); $post_author_description=get_the_author_meta("description"); $html="<div class='clearfix' id='about_author'>\n"; $html.="<img width='80' height='80' class='avatar' src='http://www.gravatar.com/avatar.php?gravatar_id=".md5(get_the_author_email()). "&default=".urlencode($GLOBALS['defaultgravatar'])."&size=80&r=PG' alt='PG'/>\n"; $html.="<div class='author_text'>\n"; $html.="<h4>Author: <span>".$post_author_name."</span></h4>\n"; $html.= $post_author_description."\n"; $html.="</div>\n"; $html.="<div class='clear'></div>\n"; $html.="</div>"; $content .= $html; } return $content; }
Checking for the Existence of a Gravatar
If you request a Gravatar image and the email you request doesn’t have an account in the Gravatar system it returns a default image to you. In some cases this might not be what you want, instead, you might want to know whether you will get back a real gravatar or if it will just be the default. Sometime, you don’t want to display avatar element instead of default avatar if users don’t have gravatar exists in your email.
WordPress Codex shows you a trick that check the header response. Return false if code response is not match with 202. Thus, you can use the Boolean value to decide display or not.
<?php function validate_gravatar($email) { // Craft a potential url and test its headers $hash = md5($email); $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404'; $headers = @get_headers($uri); if(!preg_match("|200|", $headers[0])) { $has_valid_avatar = FALSE; } else { $has_valid_avatar = TRUE; } return $has_valid_avatar; } ?>
User Avatar Photos in WordPress
WordPress has supported Gravatars for awhile, which is great, but in some cases, you want to display users avatar as their uploaded photos.
First, download and install User Photo plugin, then use code below to display their photo:
if(function_exists('userphoto_the_author_thumbnail')) { userphoto_the_author_thumbnail(); }
Avatar Display for Logged In Users
This simple code help to display the avatar of current logged user.
<?php global $current_user; get_currentuserinfo(); echo get_avatar( $current_user->ID, 128 ); ?>
Add Local Avatar
Adds local (private) avatars for your users. Maybe your users don’t want a global avatar, aren’t IT savvy enough to set a Gravatar up, simply want a private avatar for your blog, or any other reason too…
WP-Gravatar Plugin
This plugin lets you use Gravatar, MyBlogLog, OpenAvatar, Wavatar, Identicon, monsterID or Favico.ico files with your comments. But thats not all, this plugin provides you many features: gives you a Widget with your profile info and your gravatar, gives you the option to show an about the author box with posts shown on single page, let’s you show the Gravatar, OpenAvatar, Wavatar, Identicon, monsterID avatars in the Edit Comment section of your admin pages…
Download: WP-Gravatar
WP-SnapAvatar
When people comment in your blog but they don’t have avatar, such as gravatar… this plugin will allows us to take a snapshot of their website for the replacement.
Download: WP-SnapAvatar
jQuery Comment Preview
Live comment preview without page reboot. Works on jQuery.








WOW, very useful.
Thanks for your sharing.
thank for the great post
very useful
Nice post Lam! Thanks for sharing this. I’m always looking for more WordPress snippets that can make my website better.
By the way, I love the design of your blog. Very clean!
Great post can come in handy for the new design. Thnx for sharing.
Thank you guys!
Hi Lam , i enjoyed reading this post. It gave some interesting new insights.
Thank you.
helpful tutorial, thanks for the post..
All the hacks are nice. Thanks for sharing.
Great Post, Lam. Thank you very much.
The code for Avatar Display for Logged In Users.
Do you have a code that will display ALL logged in users?
So easy and helpfull for me. Thanks a lot
Great Post, thank u very much.
Thanks Lam. You are THE BOMB! I figure YOU would know, of anyone, how I might set up a blog where each user’s avatar pictures could be customized by the administrator, perhaps with different borders, or associated graphics, to indicate different hierarchies. For example, a user with a certain number of comments would get rewarded with a hi-profile notable change to the look of their avatar (?yellowStar or blueBorder, etc.)
Nice post. I’ve bookmarked it as a reference for WordPress.
Thanks Lam. The Avatar Display for Logged In Users hack is just what I needed. Thx for sharing.
Nice roundup, your site had the code I needed, good work!