get current user first and last name wordpress
You can use the following code to get the current user's first and last name in WordPress:
$current_user = wp_get_current_user();
$first_name = $current_user->first_name;
$last_name = $current_user->last_name;
Explanation for each step:
wp_get_current_user()
: This function retrieves the current user object. It returns the current user's data as an instance of the WP_User class.$current_user->first_name
: This line accesses thefirst_name
property of the current user object, which contains the first name of the user.$current_user->last_name
: This line accesses thelast_name
property of the current user object, which contains the last name of the user.
By using the above code, you can retrieve the first and last name of the current user in WordPress.