Show user avatar on page?

Hey there, just moved across from Oxygen Builder and getting used to the builder.
I am trying to add a user avatar to the nav bar once logged in and can’t seem to find it in dynamic data. Only gives me the option to show a post image or a product image?
Tried the {wp_user_picture} in text box but also not working.

Can someone tell me how to do this please?
Regards
Jeff

Hi @HansenRdDesignStudio,

afaik this is not possible with a built in solution at the moment, because as you say, the avatar is not available (you can request this as a feature on the idea board) and there is no conditional logic (it is already on the roadmap) to check if a user is logged in.

But you can use a simple php snippet to get this solved. Add a code element where you want to show the avatar, set it to execute and paste this code:

<?php 
    if ( is_user_logged_in() ) {
        $current_user = wp_get_current_user();
        if ( ($current_user instanceof WP_User) ) {
            echo 'Welcome : ' . esc_html( $current_user->display_name );
            echo get_avatar( $current_user->ID, 32 );
        }
    }
?>

To adjust the size of the avatar, you can change the number 32 within the ‘get_avatar’ function to default which is 96 and max size is 512.

Additionally, you can add you own html markup and style it with custom css.

Best Regards,
timmse

1 Like