Home › Forums › General Issues › get_field() — noob problems with Brizy › Reply To: get_field() — noob problems with Brizy
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.
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.