Join the Voxel Guide Community!

Get Involved

Display Current Logged in User Role

Description/Instructions

This will show the current user role.

If this snippet helped, feel free to buy me a taco :)

function display_user_role_shortcode() {
// Check if user is logged in
if (is_user_logged_in()) {
// Get the current user object
$user = wp_get_current_user();

// Get the roles assigned to the user
$roles = (array) $user->roles;

// Convert roles array into a readable string with each role capitalized
$roles_list = array_map('ucfirst', $roles);
return implode(', ', $roles_list);
} else {
// Return nothing if user is not logged in
return '';
}
}

// Register shortcode with WordPress
add_shortcode('display_user_role', 'display_user_role_shortcode');

  • PHP
Copy Code

Instructions

Shortcode to put in elementor.

[display_user_role]

  • HTML
Copy Code

Let's Chat About this Snippet

Chat Toggle
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Voxel Guide AI
Ask me anything about Voxel!
Send
Powered by AI24