How do I get the user firstname in wordpress?
11,219
Try this code to get user first name and last name.
<?php
$user_info = get_userdata(get_current_user_id());
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
echo "$first_name $last_name";
?>
Author by
user585148
Updated on August 30, 2022Comments
-
user585148 over 1 year
Here's my code in wordpress functions.php. I want to display user information in gravity form fields The top function works but the bottom doesn't and I can't figure out what to use to display first name.
add_filter('gform_field_value_pm_id', 'populate_pm_id'); function populate_pm_id($value){ return $user_ID = get_current_user_id(); echo $user_ID = get_current_user_id(); } add_filter('gform_field_value_pm_firstname', 'populate_pm_firstname'); function populate_pm_firstname($value){ return $user_info->first_name = get current_user_first_name(); echo $user_info->first_name = get_current_user_first_name(); }
-
user585148 almost 9 yearsThanks! Seems like it should be working now, but I'm getting a related error. I've started another thread at stackoverflow.com/questions/30020237/… if you'd like to take a look.