Support

Account

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

  • @teegee

    This code will only show an image if one is available:

    <?php $image = get_field('image');
    if( !empty( $image ) ): ?>
        <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
    <?php endif; ?>

    So to extend this:

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

    If no image is set, the whole div with the class hide-me will not be shown