Using WordPress ‘get_profile()’ PHP function

The get_profile() WordPress PHP function retrieves user data based on a specified field.

Usage

get_profile($field, $user_id = false);

Parameters

  • $field (string) – The user meta field you want to retrieve.
  • $user_id (int|false) – The user ID to retrieve the field for. Default is false (current user).

More information

See WordPress Developer Resources: get_profile

Examples

Get display name of current user

This example retrieves the display name of the current user.

$display_name = get_profile('display_name');
echo "Hello, " . $display_name . "!";

Get first name of a specific user

This example retrieves the first name of a user with the ID of 5.

$first_name = get_profile('first_name', 5);
echo "Welcome, " . $first_name . "!";

Get last name of current user

This example retrieves the last name of the current user.

$last_name = get_profile('last_name');
echo "Hello, Mr./Ms. " . $last_name . "!";

Get email address of a specific user

This example retrieves the email address of a user with the ID of 7.

$email = get_profile('user_email', 7);
echo "Send an email to: " . $email;

Get website URL of current user

This example retrieves the website URL of the current user.

$website_url = get_profile('user_url');
echo "Visit my website at: " . $website_url;