0

I have a meta box setup that allows the article creator to post a link to the forum topic of the same article subject. I display this meta data with the following:

<div class="discuss">
    <a href="<?php echo get_post_meta( $post->ID, 'true_title', true ); ?>">Discuss...</a>
</div>

Is there an if statement I could use so that if there is meta data to display, then it shows the button, but if not, it simply removes the button?

1

Check to see if it's empty before you show the div.

<?php $true_title = get_post_meta( $post->ID, 'true_title', true ); ?>

<?php if( ! empty( $true_title ) ) : ?>

  <div class="discuss"><a href="<?php echo $true_title;  ?>">Discuss...</a></div>

<?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.