I’m using a function to display logged-in user name in wordpress navigation menu and I would like to also display logged-in user avatar in the menu but couldn’t find a way to do this. So I’m asking for some help 🙂
Here is the function I’m using for the name:
function my_dynamic_menu_items( $menu_items ) {
foreach ( $menu_items as $menu_item ) {
if ( '#current-username#' == $menu_item->title ) {
global $shortcode_tags;
if ( isset( $shortcode_tags['current-username'] ) ) {
// Or do_shortcode(), if you must.
$menu_item->title = call_user_func( $shortcode_tags['current-username'] );
}
}
}
return $menu_items;
}
add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items' );
I have this code in my functions.php and I call it with #current-username# in a menu item, is there a way to customise this code to also output the avatar? Thanks for any help.
try this :
echo get_avatar( $id_or_email, $size, $default, $alt );
you can display user name as like.