Show user avatar
-
How to show an avatar on the account/section=dashboard page like on the /login/ page after logging in?
-
Hi @ulenka1984,
I understand that you’re looking to display an avatar on the account/dashboard page, similar to the one shown on the login page, after logging in using the WP User Frontend plugin.
To achieve this, you need to customize the template of the WP User Frontend plugin. I hope you understand.
Regards!
Please tell us how to customize the WP User Frontend plugin template?
I copied the file
/wp-content/plugins/wp-user-frontend/templates/account.php to /wp-content/themes/twentytwenty-child/wpuf/account.php
and added the code from the logged-in.php file to it
<div class="wpuf-user-loggedin"> <span class="wpuf-user-avatar"> <?php echo get_avatar( $user->ID ); ?> </span> <br> <h3> <?php printf( esc_html( __( 'Hello, %s', 'wp-user-frontend' ) ), esc_html( $user->display_name ) ); ?> </h3> <?php printf( esc_html( __( 'You are currently logged in! %s?', 'wp-user-frontend' ) ), wp_loginout( '', false ) ); ?> </div>
But the avatar and username are not displayed on the /account/ page although they are displayed on the /login/ page. What did I do wrong?
Hi, Thank you for reaching out and providing details on the steps you’ve taken. Troubleshooting WP User Frontend template issues can be a bit complex, but you can try to identify potential issues step by step:
- Double-check the file path and names. Make sure there are no typos or mistakes in the path and filename.
- Confirm that the file
account.php
is in the correct location:/wp-content/themes/twentytwenty-child/wpuf/account.php
. - Ensure that you’ve added the code from
logged-in.php
correctly intoaccount.php
. Check for any syntax errors or misplaced code. - Confirm that the code you added from
logged-in.php
is relevant to displaying the avatar and username. It’s possible that the code fromlogged-in.php
relies on specific conditions that are not met on the/account/
page.
I hope this will help to resolve this issue. However, if the issue persists even after following the aforementioned steps, I highly recommend consulting with a good developer.
Regards!
I may have added the code incorrectly to the account.php file.
Here is the code for my account.php file<div class="wpuf-dashboard-container"> <nav class="wpuf-dashboard-navigation"> <ul> <?php if ( is_user_logged_in() ) { foreach ( $sections as $section => $label ) { // backward compatibility if ( is_array( $label ) ) { $section = $label['slug']; $label = $label['label']; } if ( 'subscription' == $section ) { if ( 'off' == wpuf_get_option( 'show_subscriptions', 'wpuf_my_account', 'on' ) || 'on' != wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) { continue; } } if ( 'billing-address' == $section ) { if ( 'off' == wpuf_get_option( 'show_billing_address', 'wpuf_my_account', 'on' ) || 'on' != wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) { continue; } } $default_active_tab = wpuf_get_option( 'account_page_active_tab', 'wpuf_my_account', 'dashboard' ); $active_tab = false; if ( ( isset( $_GET['section'] ) && $_GET['section'] == $section ) || ( !isset( $_GET['section'] ) && $default_active_tab == $section ) ) { $active_tab = true; } $active = $active_tab ? $section . ' active' : $section; echo sprintf( '<li class="wpuf-menu-item %s"><a href="%s">%s</a></li>', esc_attr( $active ), esc_attr( add_query_arg( [ 'section' => $section ], get_permalink() ) ), esc_attr( $label ) ); } } ?> </ul> </nav> <div class="wpuf-dashboard-content <?php echo ( !empty( $current_section ) ) ? esc_attr( $current_section ) : ''; ?>"> <?php if ( !empty( $current_section ) && is_user_logged_in() ) { do_action( "wpuf_account_content_{$current_section}", $sections, $current_section ); } ?> </div> </div>
Please write how to correctly add this code from the logged-in.php file
<div class="wpuf-user-loggedin"> <span class="wpuf-user-avatar"> <?php echo get_avatar( $user->ID ); ?> </span> <br> <h3> <?php printf( esc_html( __( 'Hello, %s', 'wp-user-frontend' ) ), esc_html( $user->display_name ) ); ?> </h3> <?php printf( esc_html( __( 'You are currently logged in! %s?', 'wp-user-frontend' ) ), wp_loginout( '', false ) ); ?> </div>
- The topic ‘Show user avatar’ is closed to new replies.