I want to hide
section “softdown” if custom field is not specified

Rate this post

I want to hide the Div section if the custom field is not selected or empty!

<div class="softdown">
  <span class="postdownlink">
    <i class="fa fa-download" aria-hidden="true"></i><?php echo get_post_meta($post->ID, 'postdownlink', true); ?></span>



Within PHP, you can check if a variable is empty using a function called empty. So, you could do something like this:

<?php if(!empty($iamempty)){ ?>

<h1>I won't be shown</h1>

<? } ?>

So, for you to implement this into your code, you could do the following.

<?php if(!empty(get_post_meta($post->ID, 'postdownlink', true))){ ?>

<div class="softdown">
  <span class="postdownlink">
    <i class="fa fa-download" aria-hidden="true"></i>
    <?php echo get_post_meta($post->ID, 'postdownlink', true); ?>

<? } ?>

The above code will only display the div (The HTML content between the PHP tags) if the get_post_meta returns a value that is not empty.

Leave a Reply

Your email address will not be published.

Back to top button