Family Best Time >> Electronics

How to display Gravatar from user email in WordPress

Gravatar has made avatars easier. Like most WordPress websites, we also use Gravatar in comments to display the globally recognized avatar of each commenter. Don't you know what a gravatar is? Then read:What is Gravatar? Even though most sites only use Gravatars in comments, frankly you can use it anywhere you want to display any user's profile picture. For example, in the author bio box, or in the sidebar, or on the about page. In this article, we will show you how to display user email Gravatar in WordPress.

How to display Gravatar from user email in WordPress

Note:Our example was made for a membership site. So we're grabbing the email address by pulling the registered user information. However, the technique of displaying gravatar from email address remains the same.

Gravatar display from user email in WordPress template files

First, we'll show you how to display gravatar in your WordPress templates using a simple function. Add this code in your theme funciones.php file or in a site-specific plugin.

 función wpbeginner_display_gravatar () global $ current_user; get_currentuserinfo (); // Obtener dirección de correo electrónico del usuario $ getuseremail = $ current_user-> user_email; // Convertir el correo electrónico en hash md5 y establecer el tamaño de la imagen en 32 px $ usergravatar = 'http://www.gravatar.com/avatar/'. md5 ($ getuseremail). '? s = 32'; eco 'How to display Gravatar from user email in WordPress'; 

To display gravatar in your WordPress templates use this code.

 

Gravatar's display of user email in WordPress Posts, Pages and Widgets

Now let's say you have a user's email address and permission to use their gravatar on your site. But you don't have them as a registered user on your site. Or that you want to display selected users' charts in a post, page, or widget. To resolve this issue, add this code to your theme's functions.php file or a site-specific plugin:

 función wpb_display_gravatar ($ atts) extract (shortcode_atts (array ('wpb_user_email' => ",), $ atts)); if ($ wpb_user_email ==") global $ current_user; get_currentuserinfo (); $ getuseremail = $ current_user-> user_email; else $ getuseremail = $ wpb_user_email; $ usergravatar = 'http://www.gravatar.com/avatar/'. md5 ($ getuseremail). '? s = 32'; eco 'How to display Gravatar from user email in WordPress'; add_shortcode ('wpb_gravatar', 'wpb_display_gravatar'); 

What we have done in the code above is that we have modified the original wpbeginner_display_avatar function and created a shortcode. This wpb_gravatar shortcode accepts a wpb_user_email parameter. If you have specified an email address parameter in your shortcode, then it returns gravatar for the email address provided in the shortcode instead of the current user. This shortcode can be used in posts, pages and widgets. To show the gravatar of the current user use this shortcode:

[wpb_gravatar]

To display the gravatar of a user email address, use shortcode like this:

[wpb_gravatar wpb_user_email = "[email protected]"]

You can also add CSS by adding .wpb_gravatar class to your style sheet. I like this:

 .wpb_gravatar padding: 3px; margen: 3px; fondo: #FFFFFF; borde: 2px sólido #eee; 

We hope you found this article helpful in displaying gravatar from user email address in WordPress. If you have questions or comments please leave a comment.