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']) . '\');'; } ?>">
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.