Editor Usage Guide
Editor Usage Guide
Once you have added the snippet to your theme's functions.php file, you can display the current user's role anywhere on your site using a simple shortcode.
Using the Block Editor (Gutenberg)
To add the user role to a post or page using the modern WordPress Block Editor:
- Open the post or page where you want the role to appear.
- Click the (+) Insert button to add a new block.
- Search for the Shortcode block and select it.
- In the text field provided, enter the following code:
[user_role] - Update or Publish your page.
Tip: You can also type [user_role] directly into a standard Paragraph block; WordPress will automatically recognize and process the shortcode on the frontend.
Using the Classic Editor
If you are using the Classic WordPress Editor:
- Navigate to the post or page editor.
- Place your cursor in the location where you want the role to be displayed.
- Type
[user_role]directly into the visual or text editor. - Save your changes.
Practical Examples
You can wrap the shortcode in text to create a personalized experience for your members:
- Display in a welcome message:
Welcome back! Your current membership level is: [user_role]. - Use in a sidebar: Place the shortcode in a "Text" or "Shortcode" widget to show the user their role throughout the site.
Technical Notes
- Output: The shortcode returns a plain string (e.g.,
administrator,editor,subscriber). - Visibility: If a visitor is not logged in, the shortcode will return an empty value or "Guest" depending on your WordPress configuration.
- Styling: The output is unstyled by default. To style the text, wrap the shortcode in a
<span>or<div>with a custom CSS class:<span class="my-custom-role">[user_role]</span>