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=”<?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="<?php the_author_meta('twitter'); ?>" target="_blank">Twitter</a>
<?php endif; ?>

Need Your Help

Is there anywhere to “hook” the creation of a SQL Server connection?

.net sql-server

This is a long shot, but is there any way to get some of my code to run every time a SqlConnection is created in my application? I can’t think of events that are fired on connection creati...

How to drop a draggable into gridster

jquery drag-and-drop draggable gridster

Does anyone know if it is possible to drop a draggable element into gridster?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.