One way to do it is getting the author data and checking it’s role with get_userdata()
Codex
For that you will need the user ID, and you can get that with get_post_field()
Codex
You will need the post ID to use the get_post_field()
, so you can use the get_queried_object_id()
Codex
So, you would have something like:
//gets the ID of the post
$post_id = get_queried_object_id();
//gets the ID of the author using the ID of the post
$author_ID = get_post_field( 'post_author', $post_id );
//Gets all the data of the author, using the ID
$authorData = get_userdata( $author_ID );
//checks if the author has the role of 'subscriber'
if (in_array( 'subscriber', $authorData->roles)):
//show the content for subscriber role
else:
//show the content for every other role
endif;
Is there a faster/simpler way to do it? Yes
So why I gave you this ‘around the world’ solution’? Because from my experience, this way you can prevent a lot of stuff that might mess up with your result later on
So, what about another way of doing it? Since there are a few ways to do it, you can for example use the global $authordata
. You can check the globals WordPress has here