Support

Account

Home Forums ACF PRO No slashes in image URLs

Solved

No slashes in image URLs

  • Image field URLs are missing slashes. I am using an ACF image field, and I’ve tried returning both an array and an ID, and in both cases, the URL of the image file is missing the slashes. So the URL will look like:

    "http:// mysite.com wp-content uploads 2018 11 image.jpg"

    There are spaces where the slashes should be. I am using the most recent version of ACF Pro and WP, and I have no other plugins installed. I have confirmed that image URLs are correct if I add them into the main WYSIWYG editor or as featured image. I use ACF images all the time, and have never seen this issue. I’m on WP Engine hosting if that matters.

    Here’s how I’m getting the URLs:

    (array)

    $bg = get_sub_field('section_background_image'); 
    $bgurl = $bg['sizes']['large']; 
    echo $bgurl;

    (ID)

    $bgurl = wp_get_attachment_image_src( $bg, 'large' ); 
    echo $bgurl[0];

    Any ideas what might be happening here?

  • I also just tried returning the field as simply the URL (not an array or ID) and the issue exists there as well.

  • Ok, I don’t know how to explain it, but I guess my field got corrupted? I created a new image field with same settings, deleted the old field, and it worked. False alarm!

  • I have the same problem

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

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.