Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Created March 19, 2018 22:53
Show Gist options
  • Save rafaehlers/dfd132f0a45534aefb4b15e0a05fe444 to your computer and use it in GitHub Desktop.
Save rafaehlers/dfd132f0a45534aefb4b15e0a05fe444 to your computer and use it in GitHub Desktop.
Custom shortcode to display the user's Gravatar on the View based on an email field.
<?php // remove this whole line when copying this code to your theme's function.php file
add_shortcode( 'gvgravatar', 'gv_gravatar_shortcode' );
function gv_gravatar_shortcode( $atts ) {
extract( shortcode_atts(
array(
'email' => '',
), $atts )
);
$md5 = md5($email);
$image = '<img src="https://secure.gravatar.com/avatar/'.$md5.'?s=55">';
return $image;
}
// usage: inside a custom content field, add the shortcode [gvgravatar email="{Merge Tag of the form field containing the email}"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment