Display detailed user information in WordPress.

Cách tạo Button trên thanh Menu Wordpress cực kỳ đơn giản

Displaying user details on a WordPress website can enhance user experience and make visitors feel valued. This tutorial shows how to display current user details without using additional plugins. By creating a custom shortcode and adding the provided code snippet to your website, you can show information such as name, email, or role. The shortcode can be customized to display different user properties, making it easy to personalize your site. It is recommended to add the code to a Child Theme or use a Code Customizer Plugin to prevent it from being removed during theme updates. By following these steps, you can easily create a user profile page on your website.

Displaying user details, such as name, email, or role on the website can greatly enhance user experience. Whether it’s a welcome message or displaying basic user information, it helps readers feel valued when they visit your website.

Displays detailed user information

In this tutorial, we will show you how to display current user details without additional plugins. With this feature, the displayed information will automatically update for each logged-in user. You can display these details anywhere on your website that supports shortcodes.

Use code to display information

To display current user details without using a plugin, you can use the custom code snippet below and paste it directly into your WordPress site. This method allows you to create a custom shortcode that will display user information on the main page interface.

“`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’);“`

See also  Insert englishChèn code in WordPress header and footer for a maximum of 15 words.

Related properties

Here are some examples of how to use a shortcode with attributes and the information it will display 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 site with user information automatically.

Incorporate the code into the Web page

To integrate the above code into your website, you can access the functions.php file of the theme in use. However, this method is not recommended because theme updates can remove the code, making the shortcode unusable. To fix this, you can create a Child Theme or use a Code Customizer Plugin.

You can do this by navigating to Interface > File editor in the WordPress dashboard, then copy the above code and paste it at the end. Once you’ve added the code snippet, click the button Update File for new updates.

Show users

Please use the shortcode and display the current user’s details in your preferred location. I used the shortcode multiple times with various attributes to create a simple user profile page. These attributes include user_login, display_name, user_firstname, user_lastname, and user_email. Once done, check the results on the WordPress homepage. If you are logged in to your account, you will see all the necessary information as shown below.

Conclusion

The tutorial has helped you display current user details without the need for additional plugins, ensuring information updates automatically for each logged-in user. By taking advantage of the shortcode, you can easily display these details anywhere on your website, enhancing personalization and user engagement, you can display user information below the post related for better personalization.

Rate this post

Related posts