Home Forums ACF PRO No slashes in image URLs Reply To: No slashes in image URLs

  • In case anybody else finds this, I had the same issue when displaying an image as a background image. I was using something like:

    <?php if ($photo) { echo 'background-image: url("' . esc_url($photo['url']) . '");'; } ?>">

    Turns out the double quotes within the url(“”) caused the file name to output without slashes. I believe that’s valid CSS but I guess PHP doesn’t like it. Solved it by removing the double quotes:

    <?php if ($photo) { echo 'background-image: url(' . esc_url($photo['url']) . ');'; } ?>">

    Or by using single (escaped) quotes:

    <?php if ($photo) { echo 'background-image: url(\'' . esc_url($photo['url']) . '\');'; } ?>">