Created
March 19, 2018 22:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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