Display Author Role in author box
-
I am trying to display the author role in the author box next to their display name. I have the following in my functions.php file:
function get_author_role() { global $authordata; $author_roles = $authordata->roles; $author_role = array_shift($author_roles); return $author_role; }
And the following in my single.php file in the author box area:
<h4 class="author-name"><?php the_author_meta( 'display_name' ); ?><?php echo " , " .get_author_role(); ?>
It works great except it displays the role name in lowercase, for example, Administrator displays as administrator.
I have set up custom roles such as Publisher, Correspondent, Staff Writer, etc. I want to be able to display the role’s display name rather than the role name.
I tried adding the following to my functions.php file:
if ($author_role == 'publisher' { echo 'Publisher'; } elseif ($author_role == 'editor') { echo 'Editor'; } elseif ($author_role == 'staff-writer') { echo 'Staff Writer'; } elseif ($author_role == 'contributor') { echo 'Contributor'; } elseif ($author_role == 'correspondent') { echo 'Correspondent'; }
But it still shows the author role name, not the display name. Am I doing something wrong or should I be calling another function? Not sure if there is an author_display_role or anything.
The page I need help with: [log in to see the link]
- The topic ‘Display Author Role in author box’ is closed to new replies.