0
<div class="full-width awards">
    <h2><span>Awards</span></h2>
    <div id="accordion" class="accordion awards-list">

    <?php if (get_field( 'awards_&_festivals' ) ) : ?>

    <h3 class="award-title" ><span class="down-icon">Awards &amp; Festivals</span></h3>
    <div class="award-content" >
        <?php the_field( 'awards_&_festivals' ); ?>
    </div>

    <?php endif; ?>

</div>

I wanted to hide the awards div when the_field does not have any content any idea on how to make this happen? Much appreciated.

Nytrix
  • 1,139
  • 11
  • 23
Redondo Velasco
  • 103
  • 1
  • 8
  • Possible duplicate of [How do I check if an HTML element is empty using jQuery?](http://stackoverflow.com/questions/6813227/how-do-i-check-if-an-html-element-is-empty-using-jquery) – Anthony Jan 10 '17 at 03:57
  • To begin with you have 3 opening `div` tags and you only have 2 closing. – Nytrix Jan 10 '17 at 03:58
  • Which div you want to hide? – Akshay Jan 10 '17 at 04:08
  • where is the_field ? – harry Jan 10 '17 at 04:19
  • Since `the_field($field_name)` is equal to `echo get_field($field_name);` as noted in the docs, you can easily do as the docs demonstrates and use `if(get_field($field_name)) { //show html section here }` and not print anything at all for that section if empty. Then you don't have to rely on browser features that can be disabled by the user if desired. – Rasclatt Jan 10 '17 at 05:02

3 Answers3

1

With css you can hide it with :empty property

like

.someClass:empty {
    display:none;
}
Jishnu V S
  • 8,164
  • 7
  • 27
  • 57
1

We can do it like this -

if ($(".award-content").html() == "") {
    $('.awards').hide();
}
Vee Mandke
  • 578
  • 1
  • 11
  • 28
0

You can verify with PHP if has content and ignore div. With CSS you can use :empty selector http://www.w3schools.com/cssref/sel_empty.asp

.award-content:empty {
    display: none;
}

Or change you PHP code:

<div class="full-width awards">
    <h2><span>Awards</span></h2>
    <div id="accordion" class="accordion awards-list">

    <?php if (!empty(get_field( 'awards_&_festivals' ) )) : ?>

    <h3 class="award-title" ><span class="down-icon">Awards &amp; Festivals</span></h3>
    <div class="award-content" >
        <?php the_field( 'awards_&_festivals' ); ?>
    </div>

    <?php endif; ?>

</div>
rafaelfndev
  • 679
  • 2
  • 9
  • 27