Home › Forums › Front-end Issues › Background image not showing Front end › Reply To: Background image not showing Front end
Hi there,
Looks like you’ve misused the_field() function in your CSS.
Please try the code below.
$image = get_field('background_image');
if( $image ): ?>
<style type="text/css">
hero {
background-image: url (<?php echo esc_url($image);?>);">"
}
</style>
<?php endif; ?>
Remember : get_field() function store a value of an ACF field.
So as you did, you could check if value is valid, then you could echo/print this value.
the_field() function directly display your acf field value within your template.
So you don’t have to echo/print the_field().
Consider using the_field() only when you’re 100% sure the value is not empty and is valid/usable.
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.