Only show link if the field has been filled
On the author page of my Wordpress site, I use this code to display the author's twitter URL:
<a href=”http://twitter.com/<?php the_author_meta(‘twitter’); ?>” target=”_blank”>Twitter</a>
The problem with this code is that it will still display the link even if the user did not fill in the Twitter field in their backend profile. How can I make so that it will only display if the user have filled in their twitter?
I would presume a basic PHP IF statement would be the solution?
Simple. You can use get_the_author_meta to get the value of that meta (not as the_author_meta which prints the value). Then , compare it to "" (empty string) , and if it's not empty - echo the link, otherwise...., well we don't have otherwise - it just won't print the link.
<?php if(get_the_author_meta('twitter') != ""): ?> <a href="http://www.twitter.com/<?php the_author_meta('twitter'); ?>" target="_blank">Twitter</a> <?php endif; ?>