• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2662

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

How To Get The URL To a Gravatar Image

You’ve probably seen the following encoded URL before like this:

//0.gravatar.com/avatar/d5279c8b66d25549a0ec3c8dd46a3d1a?s=120

This URL enables you to link to a Gravatar image using the encoded email address of the Gravatar account. However, you need to MD5 hash the email address for the Gravatar account to get the hash.

All Gravatar URL’s are based on the use of the hashed value of an email address.

To create a hash, follow these 3 simple steps:

  1. Trim leading and trailing whitespace from an email address
  2. Force all characters to lower-case
  3. md5 hash the final string

You can then use the hash to request the image using code like this:

add_action( 'loop_start', 'print_gravatar_image' );
function print_gravatar_image() {

$gravatar = '//0.gravatar.com/avatar/d5279c8b66d25549a0ec3c8dd46a3d1a?s=180';

printf( '<img src="%s" />', esc_url( $gravatar ) );
}

Or like this in a template file for default themes like Twenty Sixteen.

<?php
$gravatar = '//0.gravatar.com/avatar/d5279c8b66d25549a0ec3c8dd46a3d1a?s=180';
printf( '<img src="%s" />', esc_url( $gravatar ) );
}
?>

Related Tutorials

  • Gravatar – A Globally Recognized Avatar

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Recent Posts

  • How To Translate the Property Details Additional Features Text In AgentPress Pro
  • Unlink All Archive Links For Each Entry On Per Post Basis
  • Show a Message at The Top of Your Page For New Site Visitors Using a Cookie
  • If WooCommerce Product Out Of Stock, Show Widget
  • Using get_post_meta In Replace of ACF Repeater Sub Field Functions

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems