Display Examples
Display Examples
The [user_role] shortcode dynamically detects the role of the user currently viewing the page and renders it as plain text. This allows you to create personalized messages or administrative dashboards that reflect the user's permissions.
Standard Role Mapping
Below are examples of how the shortcode renders for the default WordPress user roles:
| User Type | Shortcode in Editor | Frontend Output |
| :--- | :--- | :--- |
| Site Admin | Your role: [user_role] | Your role: administrator |
| Content Editor | Your role: [user_role] | Your role: editor |
| Blog Author | Your role: [user_role] | Your role: author |
| Regular Subscriber | Your role: [user_role] | Your role: subscriber |
Usage in Content
You can place the shortcode anywhere shortcodes are processed, such as inside Paragraph blocks, Heading blocks, or Text widgets.
Editor Input:
Hello, you are currently logged in as a/an [user_role].
Frontend Result (Logged in as Editor):
Hello, you are currently logged in as a/an editor.
Styling the Output
Because the shortcode returns the role as a raw string, you can wrap it in HTML elements to apply custom CSS or highlight the user's status.
Example: Creating a Role Badge In your page editor (using a Custom HTML block or the Code editor):
<div class="user-status">
Current Access Level: <strong>[user_role]</strong>
</div>
Resulting CSS Styling:
/* Example CSS to capitalize the role and add a color */
.user-status strong {
text-transform: capitalize;
color: #d63638; /* WordPress Admin Red */
background: #f0f0f1;
padding: 2px 6px;
border-radius: 4px;
}
Support for Custom Roles
If your site uses third-party membership plugins or custom code to create new roles (e.g., "Premium Member", "Store Manager", or "Student"), the shortcode will automatically display the unique slug of those roles.
- Role Name: Store Manager $\rightarrow$ Output:
store_manager - Role Name: VIP Member $\rightarrow$ Output:
vip_member
Note: If a visitor is not logged in, the shortcode will return an empty string by default, ensuring no broken text appears for guest users.