这应该可以做到:
$user = get_current_user_id();
$userdata = get_userdata($user);
$firstName = $userdata->first_name;
echo $firstName;
请记住,这只在用户登录时有效,因此最好在其周围设置一个条件进行检查,例如:
$user=get_current_user_id();
if($user) {
$userdata = get_userdata($user);
$firstName = $userdata->first_name;
echo $firstName;
}