display author role?
-
I want to display the Role of each author on their posts. How can I do this?
Putting the author’s name at the top of the post is easy enough, using this:
<?php the_author(); ?>
Is there something similar that I can use to show the author’s Role?
The only thing I have found online is this:
function get_the_author_role() {
global $wpdb, $wp_roles, $authordata;if ( !isset($wp_roles) )
$wp_roles = new WP_Roles();foreach($wp_roles->role_names as $role => $Role) {
$caps = $wpdb->prefix . ‘capabilities’;
if (array_key_exists($role, $authordata->$caps))
return $Role;
}
}/**
* Echo the account role of the author of the current post in the Loop.
* @see get_the_author_role()
* @return null
*/
function the_author_role() {
echo get_the_author_role();
}But I can’t make it work.
Isn’t there something shorter?
- The topic ‘display author role?’ is closed to new replies.