10 Useful Code Snippets And Plugins To Spice Up WordPress Avatar

written by aext on December 1, 2009 in Roundup with 46 comments

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.

Change the Default Gravatar in WordPress

mystery-man-icon-intro
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'); ?>

Source: WP Recipes

Automatically insert author bio on each post

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;

}

Source: AEXT.NET

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;
}

?>

Source: WordPress Codex

User Avatar Photos in WordPress

userphoto_wordpress_plugin

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();

    }

Source: D’Arcy Norman dot net

Avatar Display for Logged In Users

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

screenshot-3

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…

Download: Add Local Avatar

WP-Gravatar Plugin

screenshot-2

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

screenshot-4

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

screenshot-1

Live comment preview without page reboot. Works on jQuery.

Download: jQuery Comment Preview