How to Get Logged-in User‘s Info in WordPress for Personalized Results

Here is my expanded guide on how to get a WordPress user‘s details for personalized experiences:

Personalized content is hugely effective. According to industry research, personalized emails deliver 29% higher open rates compared to bulk messages. Applying this concept to your WordPress site can also boost engagement and satisfaction.

But how can you tailor content for individual users in WordPress? The secret is utilizing data on the currently logged-in visitor. In this post, I‘ll explain how to access user details to provide customized messages, recommendations and functionality.

Why Personalize the User Experience?

After 15+ years of building WordPress sites professionally, I‘ve seen firsthand the power of personalization. Users love seeing their name pop up on your site or getting tailored content suggestions. It makes your brand more memorable and creates a deeper connection.

Some examples of personalization I‘ve implemented for clients include:

  • Greeting users by their first name once logged in

  • Showing the number of comments they‘ve left on the site

  • Displaying their most recent comments or activity

  • Recommending posts based on past reading history

  • Allowing users to save "Favorite" articles to a personal list

Small touches like these can dramatically boost engagement over time. Users spend more time on sites that feel customized to their interests and habits.

Introducing get_currentuserinfo()

So how can you access details about the current visitor to enable personalization in WordPress? The function you need is:

get_currentuserinfo()

Adding this to your theme will populate the global variable $current_user with an object containing information on the logged-in user.

For example:

<?php

  global $current_user;
  get_currentuserinfo();

?>

Now you can use $current_user->user_login to get their username, $current_user->user_email for their email address, etc.

But there‘s an important catch…

Checking if the User is Logged In

The get_currentuserinfo() function will only work if a user is actively logged into your site.

So you need to wrap it in a conditional check like:

if ( is_user_logged_in() ) {

  // Call get_currentuserinfo()

}

This prevents errors being shown to visitors who aren‘t logged in. Inside the conditional is where you can safely display personalized messages or content.

Accessing User Data Fields

Once you‘ve called get_currentuserinfo(), the $current_user object contains a variety of useful fields:

  • user_login – The user‘s username
  • user_firstname – Their first name
  • user_lastname – Their last name
  • user_email – The user‘s email address
  • ID – The numeric ID of the user

And more! Here‘s an example using the first name field to show a customized welcome message:

<?php

  if ( is_user_logged_in() ) {

    global $current_user;
    get_currentuserinfo();

?>

<h2>Welcome, <?php echo $current_user->user_firstname; ?>!</h2>

<p>We‘ve got some great new articles for you to check out.</p>

<?php } ?>

You can output virtually any user data field in a similar way to create personalized experiences.

Creative Personalization Ideas

Combining get_currentuserinfo() with conditionals allows tailored content in WordPress. Here are just a few creative ways I‘ve used it over the years:

  • Recent Activity – Show the user‘s 5 most recent comments or posts. Keep them engaged with relevant content.

  • Recommendations – Suggest posts based on their past reading history using a plugin like Recommended Content for WP.

  • Favorites – Let users save posts to a custom "Favorites" list for quick access later.

  • Social Integrations – Display Facebook profile info, recent Tweets and more with a plugin like WordPress Social Login.

  • Custom Navigation – Highlight menu items based on user role, preferences or past activity.

The possibilities are endless! Start small by greeting users by name, then gradually build up the personalization over time.

In Closing

While simple, get_currentuserinfo() unlocks powerful opportunities for engagement on WordPress sites. Personalized experiences feel tailored, satisfying and rewarding for each user.

So put your visitors first with custom messages, content and functionality. Get creative in showing you know them! Let me know if you have any other questions on advanced WordPress personalization.

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.