Block Editor Integration
Integrating with the Block Editor (Gutenberg)
The Show User Role snippet is fully compatible with the WordPress Block Editor (Gutenberg). Since the functionality is delivered via a shortcode, you can place the user's role anywhere within your page or post layouts using standard WordPress blocks.
Using the Shortcode Block
The most reliable way to display a user's role within the Block Editor is by using the dedicated Shortcode block.
- Open the page or post where you want to display the role.
- Click the (+) Insert button and search for "Shortcode".
- Add the block to your layout.
- Input the following tag into the text field:
[user_role]
Implementation in Text Blocks
You are not limited to the Shortcode block. The [user_role] tag can also be embedded directly into text-based blocks to create more natural, personalized sentences.
- Paragraph Block: "Welcome back! Your current access level is:
[user_role]" - Heading Block: "Dashboard for
[user_role]" - List Block: Great for account summary pages.
Example Usage
To create a personalized welcome banner, you might combine a Heading block with the shortcode:
<!-- Paragraph Block Example -->
Hello, you are currently logged in as a **[user_role]**.
Important Considerations
- Frontend Rendering: The user role will only render its value on the live website (frontend). Inside the Gutenberg editor interface, the shortcode will appear as plain text
[user_role]. - Dynamic Visibility: The role displayed is specific to the user currently viewing the page. If a visitor is not logged in, the shortcode will return an empty string or nothing, depending on your WordPress configuration.
- Styling: The output of
[user_role]is raw text. To style it (e.g., change color or font weight), wrap the shortcode in a Paragraph block and use the Block Editor's sidebar settings to apply typography and color styles.