You can use the main WP_Roles
object to get an array of role names/labels, e.g.
$role="author";
$label=""; // if there is no label this will be used instead
if ( wp_roles()->has_role( $role ) ) { // this protects us if the role does not exist.
$role_names = wp_roles()->get_names();
$label = $role_names[$role]; // Author
}
echo $label; // prints Author not author
translate_user_role
will translate it into the currently configured locale if available.
Here’s the output of get_names()
:
wp> wp_roles()->get_names();
=> array(14) {
["administrator"]=>
string(13) "Administrator"
["editor"]=>
string(6) "Editor"
["author"]=>
string(6) "Author"
["contributor"]=>
string(11) "Contributor"
["subscriber"]=>
string(10) "Subscriber"
....
Related Posts:
- Create a function to display HTML/data based on site admins role?
- How to display total user count by specific role in WordPress as statistics?
- Conditionally Loading JavaScript/CSS for Shortcodes
- Show shortcode without executing it
- How to create a shortcode with 1 parameter (atts)
- How does a shortcode work?
- Run visual composer code in php page
- Remove wptexturize from a shortcode?
- Using shortcode in Post title
- Shortcodes, HTML tables, and multiple rows
- Audio or playlist shortcode condition according to the amount of files on attachment page
- Does a shortcode with a single attribute have to use an array?
- WP_enqueue_script inside shortcode?
- template_redirect to accompany with a shortcode
- Use [shortcode=”value”] instead of [shortcode att=”value”]?
- Tinymce shortcodes within shortcode contents
- I dont want to show shortcode in tag
- Post loop created via shortcode not displaying shortcode in content
- Pass shortcode variables to template
- passing multiple parents value into a shortcode
- Is it possible to add a repeater field to TinyMCE’s option window?
- How do I preview the result of a shortcode in the TinyMCE editor?
- Shortcodes: Pros and Cons
- esc_attr not working in shortcode
- Raw output (preventing wpautop)
- Conditionally loading Facebook PHP SDK in shortcode
- Can’t understand $atts in functions?
- Are .MP3 files with capital letter extensions allowed in [audio] shortcode?
- How to handle shortcodes when using the JSON API
- Are shortcode functions applied while rendering the content, or are they executed and stored with the post content?
- is_admin() returns false in save_post hook with Gutenberg editor
- Why are Shortcodes Disabled in Widgets by Default?
- Get Posts shortcode plugin and meta_query?
- possibility to control embedded video timeline with buttons and links external to the player
- Add custom setting that uses radio button to WP Gallery
- WordPress Gallery shortcode: Display one category ID only
- How to get gallery id inserted to a post?
- WordPress Shortcode show database row
- Custom shortcode is not working in text widget
- Shortcodes won’t work on live environment
- Use shortcodes in terms description? [closed]
- Adding to the_content or a variable from within a shortcode function
- Shortcode: text content ends up outside html tags
- How to wp_redirect on ‘init’ hook on condition of current post id?
- PHP Running On CMS Side of WordPress
- Create a shortcode to use in visual editor
- Basic do shortcodes question
- What is this format called (nested shortcodes)?
- Problem with height in video shortcode
- Shortcode not showing $content in correct place
- Best tools for preparing and styling a table [closed]
- When are Shortcode Attributes Available in Template
- Best way to include reusable sections in page content
- How can I insert a shortcode in the title tag of another?
- Shortcode inside text widget do not call enqueue style
- How to create a dropdown of shortcodes in edit mode for posts
- How to execute a shortcode outside the post content/entry in a theme?
- Metabox Keeps Stripping Parts of Shortcode
- Form processing: How to process form before output and access data from shortcode
- How to Retrieve data of Gallery Shortcode and display it above a post
- Checking post content for a shortcode, but content is being returned as empty
- do_shortcode() won’t return PHP Array
- Adding my own custom woocommerce shortcode to child theme, how?
- contact form 7 :create shortcode usable in email message [closed]
- Show shortcode only in posts
- Better way to display multiple plugin output on the same page?
- get_queried_object_id / short code returning blank
- Shortcode won’t take into account custom post ID put in parameter
- How to utilise multiple values from a single shortcode attribute?
- JavaScript missing from shortcode content
- shortcode to display specific recent posts
- How to test If a post has a particular term
- wp_link_pages shortcode for ‘nextpagelink’
- Multiple values for one variable
- Function in a wordpress shortcode
- nested shortcodes from different plugins. too complex? [duplicate]
- Impossible to display modification in shortcode code?
- Use Shortcode on Custom Page
- WordPress Database Error using $wpdb->get_results()
- Shortcode or Template Page
- Ajax callback and shortcode functionality
- Duplicate short code duplicating some values only
- Shortcode for External HTML
- How to implement theme shortcodes in text outside of pages?
- Video Shortcode Only Returning a Link
- Loading shortcode stylesheet only when shortcode is in text widget [closed]
- How to add a nested shortcode into editor?
- Shortcode with multiple variables
- Shortcode Attribute
- Can’t get default values to work with custom shortcode
- Question about do_shortcode
- How create a shortcode with html
- Adding shortcode [closed]
- do_shortcode autommatic content generation
- Enclosing shortcodes create line breaks
- Add the results of a custom query into a do_shortcode
- Using $variable in shortcode
- Free Add to Cart Button on WooCommerce with Elementor – No Premium [closed]
- wordpress shortcode url decode non Latin character
- Shortcode return vs echo. Return messes with data URLs, echo does not