Home › Forums › General Issues › get_field() — noob problems with Brizy › Reply To: get_field() — noob problems with Brizy
If you can setup a field, then you can do something like:
<?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; ?>
You would need to change the field name from image to whatever you need.
Or you could do something like:
<?php $image = get_field('image');
if( !empty( $image ) ): ?>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php else: ?>
<img src="url-to-placeholder" class="placeholder-class" ?>
<?php endif; ?>
That way you don’t need the jQuery, as it checks if an image exists/been added if not, uses a fall back to a placeholder image
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.