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:

  1. 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.

  2. $current_user->first_name: This line accesses the first_name property of the current user object, which contains the first name of the user.

  3. $current_user->last_name: This line accesses the last_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.