php - Show a text if the post has written by author user role in Wordpress

I search a PHP code what is show a certain text or html code on the post page when the post author is an author. (not ad

I search a PHP code what is show a certain text or html code on the post page when the post author is an author. (not admin or editor)

When the post author is an admin or editor then show nothing.

Thanks

I search a PHP code what is show a certain text or html code on the post page when the post author is an author. (not admin or editor)

When the post author is an admin or editor then show nothing.

Thanks

Share Improve this question asked Oct 12, 2019 at 3:40 Viktor NagyViktor Nagy 11 bronze badge 2
  • I'm sure what you're trying to ask for? It would be more better if you could add more explanation or some code that you've tried so far. If you're intent to ask that on front end post page is visited by author of the post and he can show some special extra peace of lines or HTML! – Vantiya Commented Oct 12, 2019 at 4:10
  • I search a PHP code: If the post author is from specific user role, (author) then show something... Else do not show anything. – Viktor Nagy Commented Oct 12, 2019 at 4:38
Add a comment  | 

1 Answer 1

Reset to default 0

This code will do it:

global $post;
$user = get_user_by( 'ID', $post->post_author );
if ( in_array( 'author', $user->roles ) ) {echo "Author";}

You don't even need global $post; if you are if a query loop.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745087795a4610509.html

相关推荐

  • php - Show a text if the post has written by author user role in Wordpress

    I search a PHP code what is show a certain text or html code on the post page when the post author is an author. (not ad

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信