show the author's role along with the name in the single.php

admin2025-04-20  0

some way to show the author's role in wordpress for example: Administrator, editor, author, contributor ect...

Let something like this be left:

This post was written by contributor JUan

I'm just using <? php the_author (); ?> but I can't think of anything else to show the role of the user assigned to a post

some way to show the author's role in wordpress for example: Administrator, editor, author, contributor ect...

Let something like this be left:

This post was written by contributor JUan

I'm just using <? php the_author (); ?> but I can't think of anything else to show the role of the user assigned to a post

Share Improve this question asked Oct 1, 2019 at 16:20 CamalietCamaliet 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

To get author role in single.php you have to get author id first. Use following code to get author id

$author_id = get_the_author_meta( 'ID' );

Then get userdata using

$user = get_user_by( 'ID', $author_id); 

or you can use

$user = get_userdata( $author_id );

now you can display role of author using :

echo implode(', ', $user_info->roles);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745114798a285799.html

最新回复(0)