WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In post loop I'd like to setup a condition for get_the_author_meta.

So if the author meta field is empty, then nothing is displayed. Below is what I have but it's not working.

<?php if(get_the_author_meta('twitter') ): ?>
<a href="https://www.twitter.com/<?php get_the_author_meta('twitter'); ?>" target="_blank">Twitter</a></p>
<?php else: ?>
<strong>No website</strong>
<?php endif; ?>
share|improve this question

get_the_author_meta() returns the data for use in PHP. To display the information instead, use the_author_meta()

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

Your code does not echo data even if it is present. Add an echo or use the_author_meta

<?php if(get_the_author_meta('twitter') ): ?>
  <a href="https://www.twitter.com/<?php echo get_the_author_meta('twitter'); ?>" target="_blank">Twitter</a></p>
<?php else: ?>
  <strong>No website</strong>
<?php endif; ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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