Home › Forums › General Issues › get_field() — noob problems with Brizy › Reply To: get_field() — noob problems with Brizy
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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.