Based on what you wrote, you should use instead :
if ( ! is_admin() ) {
function get_user_role() {
global $wp_roles;
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
foreach ( $roles as $role ) {
$user_role="<p>" . $wp_roles->roles[ $role ]['name'] . '</p>';
}
return $user_role;
}
add_shortcode( 'display_user_role', 'get_user_role' );
}
It works pretty well on my install !
Related Posts:
- create shortcode to list users with specific meta key value
- Solution to render Shortcodes in Admin Editor
- Use AJAX in shortcode
- Include PHP file in Content using [shortcode]
- Shortcode producing headers already sent error
- How to add attributes to a shortcode
- How to display random users with avatars
- Apply custom role capabilities to administrator (without plugin)
- Enabling shortcodes for custom fields
- Roles & capabilities GUI that does not create separate table
- How to use get_media_embedded_in_content function
- Can shortcodes contain conditional statements? Even without them my shortcode renders blank page
- Shortcode with parameters inside parameters
- Creating a table from shortcode avoiding wpautop for each row
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- Stripping shortcode from custom excerpt function
- how to create shortcode in wordpress
- What is wrong with this Shortcode? I get it in a wrong place inside the content
- Display random text from a file with the WP built-in AJAX API
- Set first oembed in post to a global variable or function
- Formatting post content to exclude gallery
- Remove images from get_the_excerpt
- Shortcode with custom content attribute?
- Problem with extract() with custom shortcode
- How do I redirect upon login a specific user based on role?
- Shortcode to insert menu in page body?
- Using locate-template & shortcodes doesn’t appear to work
- Displaying a random user with a shortcode
- Passing HTML in WordPress Shortcode arguments
- Adding body class when post contains a specific shortcode
- How to add another user to this remove_menu function?
- Add a new subscriber role using a function
- Function to show only first instance of shortcode
- Display a text message if the shortcode is found?
- How to test for Super Admin
- Custom roles can’t access to wp-admin
- creating shortcode to pull json array
- Custom registration URL lost when user makes signup mistake
- Custom Shortcode, functions PHP WP_Query loop
- Custom function for specific user role
- Pass Shortcode Attribute to footer Script
- Super simple shortcode not working
- Hide Author.php template from specific user role
- Detect Safari desktop browser and include the detection in a shortcode
- My simple custom shortcode is not longer working (possibly due to upgrade to WordPress 4.4 ?)
- edit role display name and label name without plugins
- Display gallery on top before content
- List child pages of specific page using shortcode
- How to extract the variables out from “add_shortcode” function?
- Display first name of logged in user?
- How to get specified parent page title in my function
- Possible to display shortcode based on the category?
- WordPress shortcode attributes for database SELECT?
- Shortcode pagination not advancing
- Variable if post is sticky in functions.php
- Having issues with a foreach inside of a shortcode with ACF gallery
- Toggle User Roles with button
- Shortcode inserts paragraphs before and after executing shortcode
- Display post shortcode content in the sidebar?
- How to change or add user role after getting post request data about pay? [closed]
- How to get the index number of the posts?
- Execute a ultimate member action when user role is updated
- Using shortcode content with nested shortcode
- How can I make a widget shortcode to control all the widgets?
- Custom shortcodes not inserting into visual composer columns
- How to filter $content in shortcode function
- Create a custom taxonomy that will be used to create and filter markers in a Google Map
- Setting youtube size in functions.php
- Adding a colorbutton in tinymce dialog with current api
- Passing variable as add_shortcode argument
- Allowing users to view private posts (pending approval)
- Display gallery on bottom after content
- Add button to kitchen sink toggle
- Excerpts are not displayed by a shortcode on category pages
- WordPress Shortcode function display outside of widget
- check if the user is owner of current page
- shortcode help require
- Allow Contributor to edit their own posts after Adm aproval
- Optimizing a WordPress site
- Help With Creating Shortcode
- Use html inside shortcode function
- How to add custom JavaScript in functions?
- How to set default post editor based on role?
- Shotcode argument issues
- Shortcode parse error – wrong syntax
- Exclude category from shortcode
- wp_nonce_field is breaking form for reasons unknown
- Visual Composer creating own shortcodes with vc_map() to return simple Image
- get_pages() Returns Only One Item
- Function shortcode – Set Parameter
- Adding an option to a shortcode
- How to use author meta in shortcode?
- Using multiple line variable inside a function?
- Testing for a shortcode using a function. 404 page throwing PHP Notice
- Use a shortcode to display custom meta box contents
- Echoing function into WordPress NextGen gallery
- Output loop to function return?
- How to echo the value of an array element using a function via a shortcode
- Wp-query Order By problem
- How to parse a shortcode within a shortcode?