WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I currently display a URL from a custom meta box, but wanted to add a conditional check, so that if nothing has been entered, not to display the link text.

<a target="_blank" href="<?php $urlbox = get_url_desc_box(); echo $urlbox[0]; ?>">Visit Website &raquo;</a>

At the moment, even when nothing is added to the URL Meta BOX, the Visit Website text still appears within the post.

share|improve this question
up vote 0 down vote accepted
$urlbox = get_url_desc_box();

if ( !empty( $urlbox[0] ) ) {
    echo sprintf( '<a target="_blank" href="%s">Visit Website &raquo;</a>', $urlbox[0] );
share|improve this answer
Thank you Ryan - perfect. – Huw Rowlands Sep 27 '12 at 9:01

You should just need to move your logic outside of the <a> tag, and create a condition to only display if the result isn't null

$urlbox = get_url_desc_box();
if ($urlbox[0] != null) { ?>
      <a target="_blank" href="<?php echo $urlbox[0]; ?>">Visit Website &raquo;</a>
<?php } ?>
share|improve this answer

Your Answer


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.