I see.
We can create a shortcode to show the user name and activate the shortcode feature in menu using this PHP snippet:
add_shortcode( 'logged_in_user_name', function() {
ob_start();
$current_user = wp_get_current_user();
printf( __( '%s', 'textdomain' ), esc_html( $current_user->display_name ) ) . '<br />';
return ob_get_clean();
} );
add_filter('wp_nav_menu_items', 'do_shortcode');
Then add [logged_in_user_name]
shortcode to your menu item:
