How to Display Detail Information of Current User in WordPress (without Plugin)

Displaying user details, such as display name, first name, email, or role, on a dedicated section of your website can significantly enhance the user experience. Whether it’s a warm welcome message on the landing page or an account menu showcasing basic user information, these personalized touches help users feel valued and recognized from the moment they arrive.

In this guide, we’ll show you how to dynamically display the current user details of your choice without the need for additional plugins that might affect your website’s performance. This means the displayed information will automatically update for each logged-in user.

You can showcase these details anywhere on your site that supports shortcodes, such as page and post editors. Let’s dive in!

Displaying User Details Without Plugin

Step 1: Copy the Code Snippet

To display current user details without using a plugin, you can seamlessly integrate a custom snippet directly into your WordPress website. This method allows you to create a custom shortcode that will display user information on the front end.

The snippet below generates the [userdetail] shortcode, which can be customized with various attributes to display specific user details.

function wpp_user_details($atts = array()) {
    $current_user= wp_get_current_user();
	
    // Check for positional attribute
    if (isset($atts[0])) {
        $detail = $atts[0];
    } else {
        // Fallback to default attribute handling
        $atts = shortcode_atts(array(
            'detail' => 0
        ), $atts);
        $detail = $atts['detail'];
    }
    $user_detail = $current_user-> $detail;
    return $user_detail;
}
add_shortcode('userdetail', 'wpp_user_details');

The Shortcode Attribute

Here are some examples of how to use the shortcode with the attribute and the information it will present on the front end:

  • [userdetail display_name] will display the user’s display name.
  • [userdetail user_login] will display the user’s username.
  • [userdetail user_firstname] will display the user’s first name.
  • [userdetail user_lastname] will display the user’s last name.
  • [userdetail user_email] will display the user’s email address.
  • [userdetail ID] will display the user’s ID.

This flexible shortcode makes it easy to personalize your website with dynamic user information.

Step 2: Incorporate the Custom Snippet

To integrate the snippet from the previous step into your website, you can quickly add the code to the functions.php file of your current active theme. However, this approach is not recommended for long-term use, as theme updates may remove the snippet, rendering the shortcode unusable. Instead, consider safer methods such as using a child theme or creating a custom plugin.

For demonstration purposes, we’ll add the snippet to the bottom of the functions.php file. You can do this by navigating to Appearance → Theme File Editor in your WordPress dashboard. (For block themes, find the Theme File Editor in the Tools menu.)

Once you’ve added the snippet, click the Update File button to enable the shortcode.

Step 3: Displaying the User’s Detail

Now it’s time to put the shortcode to use and display the current user’s details in your preferred location.

As evident from the screenshot above, we’ve utilized the shortcode multiple times with various attributes to craft a simple user profile page. These attributes include user_login, display_name, user_firstname, user_lastname, and user_email.

Now, let’s witness the outcome on the front end.

If you’re logged in and your account is fully populated with the necessary information for the shortcode attributes — unlike the default editor account, which lacks a first name and last name — you’ll see all the details displayed exactly where you’ve positioned the shortcode.

The Bottom Line

This guide has shown you how to dynamically display current user details without the need for additional plugins, ensuring that information updates automatically for each logged-in user.

By leveraging shortcodes, you can easily showcase these details anywhere on your site, enhancing personalization and user engagement.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Picture of Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to start a profitable blog with WordPress? OF COURSE!

Leave a Comment

Hey 👋🏻
Got WordPress knowledge?
Why not turning it into profit? Click the button below to learn how.

Your popup content goes here

50%

Where should we send the template?

After entering your email address, you will be added to our newsletter subscribers. You can unsubscribe anytime.

Want to Build Passive Income Like the One on the Screenshot Below?

Click the button on the right side to learn how 👉🏻
5 easy steps to turn your WordPress knowledge into monthly recurring revenue.

Click the above button to close the popup.