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

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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

  • Show Gravatar On Custom Author Archive Page Template If It Exists In Twenty Twenty
  • 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

  • Add Pagination to AgentPress Pro Listings Archive Page
  • List of Code Snippets for WooCommerce
  • Style First Nav Menu Item Using CSS
  • Genesis One Page Block Theme
  • Reposition Image Before Title When Mobile Responsive

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags