WordPress get display name

Depending on whether you have the user’s ID (If not, checkout: Get user ID in every situation) you can get the display name by creating the user object first:

// Different ways getting the user object
$user = new WP_User( $user_id );

// Current user object
$user = wp_get_current_user();

// Get user by ID, email, slug or login
$user = get_user_by( 'ID', $user_id );

// Get user data by user id
$user = get_userdata( $user_id );

When the user object is created you can simply obtain the display name from it as follows:

// Get display name from user object
$display_name = $user->display_name;
Robbert Vermeulen

Need help from a WordPress expert?

I would love to hear about your project and how I can help you achieve your goals