1

How to exclude administrators from the code below? So if the current post author has the role of administrator, nothing will show.

 <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" ><?php the_author_meta( 'display_name' ); ?></a>

thank you

3

You can use the wordpress function user_can that accepts as arguments the id of the user and a string representing a capability or a role name ('administrator' in your case ) and returns a boolean value.

http://codex.wordpress.org/Function_Reference/user_can

Referred to your code you can try this

<?php 
  if( !user_can( get_the_author_meta( 'ID' ), 'administrator' ) ): ?> 
    <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" ><?php the_author_meta( 'display_name' ); ?></a>
<?php 
  endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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