get the avatar url instead of an html img tag when using get_avatar?

It’s fairly simple to construct the Gravatar URL yourself, it’s just an MD5 hash of the user’s email address. <?php $gravatar=”http://www.gravatar.com/avatar/” . md5(strtolower($email)) . ‘&s=32’; ?> <div class=”avatar” style=”background: url(<?php echo $gravatar ?>);” ></div> The s parameter at the end there defines the size of the image in pixels. Using Gravatars – WordPress Codex

How to output nothing instead of default avatar?

You can use the get_avatar filter to change the output or avatar_defaults to add new image that can be placed on your server. Here is an example code for adding new avatar that you can set as default from the Settings > Discussion page. add_filter( ‘avatar_defaults’, ‘add_new_gravatar_image’ ); function add_new_gravatar_image($avatar_defaults) { $myavatar=”http://yoursite.com/image.png”; $avatar_defaults[$myavatar] = “Default … Read more

Listing all users by their avatars in wordpress

You can jump start by using following example. Here I’ll be listing users and loop through them to display avatar and display name. <?php $blogusers = get_users(); // Array of WP_User objects. foreach ( $blogusers as $user ) { /* Here passing user email and avater size */ echo get_avatar( $user->user_email , 96 ); echo … Read more

How to get gravatar url alone

Just generate the URL yourself. It’s just a hash of the user’s email address. function get_gravatar_url( $email ) { $hash = md5( strtolower( trim ( $email ) ) ); return ‘http://gravatar.com/avatar/’ . $hash; } This function requires that you pass the user’s email address in … but you could do anything you need to programatically … Read more

Alternative to using get_avatar function?

The get_avatar() function applies a get_avatar filter hook, that you can use to change the avatar markup: return apply_filters(‘get_avatar’, $avatar, $id_or_email, $size, $default, $alt); I think this would be the correct way to hook into this filter: function mytheme_get_avatar( $avatar ) { $avatar=”<img src=”https://wordpress.stackexchange.com/questions/22728/<” . get_template_directory_uri() . ‘/images/authors/’ . get_the_author_ID() . ‘.jpg” alt=”‘ . get_the_author() … Read more

Removing Gravatar.com support for WordPress and Simple Local Avatars

If you want a super-lightweight solution and don’t mind dabbling in a little code, drop this in your functions.php; function __default_local_avatar() { // this assumes default_avatar.png is in wp-content/themes/active-theme/images return get_bloginfo(‘template_directory’) . ‘/images/default_avatar.png’; } add_filter( ‘pre_option_avatar_default’, ‘__default_local_avatar’ ); Alternatively, if you want a bit more juice, with the ability to manage everything in the admin, … Read more