Support

Account

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.