• Resolved cari18

    (@cari18)


    I am looking for an easy way to display any user’s avatar by his user_login on any WP page? For exemple a shortcode or a complementary plugin.

    Thank you if you can help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support andrewshu

    (@andrewshu)

    Hello @cari18

    You could add this code to your functions.php file in your child theme folder:

    add_shortcode( 'um_get_avatar_shrtcd', 'um_get_avatar_shrtcd' );
    
    function um_get_avatar_shrtcd( $atts ){
    	$atts = shortcode_atts( array(
    		'username' => '',
    	), $atts );
    	$user = get_user_by('login', $atts['username']);
    	if($user){
            return um_get_avatar( '', $user->ID, 150 );
    	}
    
    	return '';
    }

    And you could use this shortcode – [um_get_avatar_shrtcd username=”USER_NAME”]

    Thank you.

    Thread Starter cari18

    (@cari18)

    Thanks a lot Andrew for your help.

    Unfortunately, when I copy this code in the function.php file of the child theme folder, I got a critical error and can’t no more access to the site.

    Could you please have a look to check the code?

    Plugin Support andrewshu

    (@andrewshu)

    Hi @cari18

    It works perfect on my site. Could you send me text of the error? (Please erase or blur all data that is confidential on the screenshot or in the error text).

    Regards.

    @cari18

    Mistake is that ”USER_NAME” has wrong double quotes for PHP by the Forum when not using the CODE formatting.

    Use [um_get_avatar_shrtcd username="USER_NAME"] instead.

    Thread Starter cari18

    (@cari18)

    Unfortunately, when I copy this code in the function.php file of the child theme folder, I got a critical error and can’t no more access to the site.

    The message is “There is a critical error on this site” and it is not possible to login.

    So at that time I didn’t yet implement the shortcode in any page

    Thread Starter cari18

    (@cari18)

    Could it be caused by a conflict with another plugin?

    @cari18

    Remove the code snippet from your theme’s functions.php.

    Enable PHP error logging, read this guide: “How to enable debug logging”

    https://docs.ultimatemember.com/article/1751-enable-debug-logging

    You will probably get a PHP log file with notices and errors in /wp-content/debug.log when you add the code snippet to your theme’s functions.php again.

    Post the content of this file here in the Forum ( use CODE formatting ) and we can give you a PHP error explanation.

    Thread Starter cari18

    (@cari18)

    I found a typing error in the code. So no more critical error.

    Thread Starter cari18

    (@cari18)

    And it works perfectly.

    Sorry for the “false mistake” and thank you !

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Display any user’s avatar by his user_login’ is closed to new replies.