1

I'd like to display some information inside a div on the single posts written by some authors. For exemple, author ID 15 has 100 posts. I'd like to display some information on that post pages, just below the header. I've tried this but it didn't work.

<?php if ( is_author( '15' )  ) : ?>
    <div class="specialist"><img src="https://xxxxxx.com.br/wp-content/uploads/2019/11/xxxx.png" /> Specialist: <?php the_author_posts_link(); ?></div>
<?php endif; ?>

1 Answer 1

0

is_author() isn't working as you expect because it checks whether the current query is for an existing author archive page.

If you're placing your code in single.php inside the loop, you can use this instead:

<?php if( $post->post_author == '15' || $post->post_author == '16' ) { ?>
    <div>Your code here</div>
<?php } ?>
6
  • Thanks for your help but it didn't work. I am inserting the code as a hook as you can see here prnt.sc/q6shcm / prnt.sc/q6si5l
    – juniorbra
    Commented Dec 5, 2019 at 19:57
  • I'm not familiar with the language used there or what type of thing you're editing. The code in this answer would go inside your theme's single.php or similar. PHP doesn't run in the editor (wp-admin) for security reasons.
    – WebElaine
    Commented Dec 5, 2019 at 20:44
  • Yes, I inserted it on single.php and worked! One more question, if I'd like to insert an information on the posts from 2 authors, the code would be how? <?php if( $post->post_author == '15,16' ) { ?>
    – juniorbra
    Commented Dec 5, 2019 at 21:50
  • Updated above with an "or" statement (the two pipe || symbols). Also note, you should only put this in a theme's single.php file if it's a custom theme or you've already created a child theme. If you just edit a theme, and later update that theme, your changes will be overwritten. By putting your edits in a child theme instead, your edits stay in place even when the parent theme gets updated.
    – WebElaine
    Commented Dec 5, 2019 at 21:53
  • Thanks, but I might be doing something wrong as the information is being displayed to all authors <?php if ( $post->post_author == '15' || '14' ) { ?> <div class="123-mbf"><img src="https://123.com/wp-content/uploads/2019/11/123.png"> Specialist: <?php the_author_posts_link(); ?></div> <?php } ?> I'd want that the information is displayed on posts from authors 14 and 15.
    – juniorbra
    Commented Dec 5, 2019 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.