Support

Account

Home Forums General Issues get_field() — noob problems with Brizy Reply To: get_field() — noob problems with Brizy

  • @teegee

    The code doesn’t go in the functions file, it goes in your template.

    Perhaps I’ve misunderstood what you need?

    What I’d like to achieve is to tell a div which has a certain class that it should not be displayed if a certain field is empty

    So looking at the supplied code:

    <style>
    .hide-me {
      display: none;
    }
    <?php $image = get_field('image');
    if( !empty( $image ) ): ?>
    <div class="hide-me">
        <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
    </div>
    <?php endif; ?>

    So in the above, we have a div tag with a class of hide-me (use whatever class name you want it to be).
    If the field (in this case image) is empty, the whole div and image will not be shown.

    You don’t need the class or style, because the if( !empty( $image ) ): is the conditional tag to show or hide the div and image if nothing has been uploaded.