1. HOT Divi Ultimate Header Plugin - More variety for your Divi header: https://header.diviultimate.com/

Image as div background

Discussion in 'Free Divi Community Forum' started by Josue Rodriguez, Jun 12, 2019.

  1. Josue Rodriguez

    Josue Rodriguez New Member

    So I am trying to setup a custom image field in a custom page template as the background of my header.
    Here is the code I am using to get the image to show:
    <?php

    $image = get_field('header_image');

    if( !empty($image) ): ?>

    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />

    <?php endif; ?>

    If I include this code in my page template by itself it shows up fine in the page, but I try to set it as a background to a div using style="background option inside the division, it won't show.

    Anyone here that can help?

    Thanks,

    Josh
     
    1. AD Create stunning carousel for Divi sites: https://divi.help/link-forums/divi-carousel.153/
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    Something like this should work:
    Code:
    <div style="background-image: url(<?php echo $image['url']; ?>) ">
     

Recommended Divi Hosting