Home Forums General Issues Image Field Return URL not Working


Image Field Return URL not Working

  • Hi I’m using ACF or Advanced Custom Fields which i saw here a while ago..

    What i want is to output a second featured image in the homepage..

    Question: 1

    `<div class=”jpl-widgets-d” style=”background: url(‘<?php the_field(‘featured_home_page_image’); ?>’) no-repeat;”>

    Is it possible to use the php tag inside an style?

    Anyway, i also tried using this code

    <img src="<?php the_field('featured_home_page_image'); ?>" alt="" />

    But it’s not working ..

    Field Name: featured_home_page_image
    Field type: Image
    Return Value: URL

    Help. thanks!

  • Hi @vinex08

    Yes, you can use PHP within the style attribute.
    PHP is a serverside language that is compiled before the HTML and then returned to the browser (client).

    Your code looks fine, the only issue may be where the data is being loaded from.

    If your home page contains a custom loop, this will affect where ACF will load data from. Perhaps you will need to specify the page that you want to load the image from via the the_field second parameter.

    You can checkout the docs for more info on thei paramter


  • I’m trying to output the image in my static Homepage …

    the image is coming from a PAGE. Page ID is 61 ..

    Anyway, i tried this …

     $page_d = 61;
        <div class="jpl-widgets-d" style="background: url(<?php the_field('featuredimg_url', $page_d); ?>) no-repeat;"></div>
  • Hi @vinex08

    Your code looks fine. Please do some debugging to understand why the value is not being returned.

    Debugging means use the get_field function and store it in a variable. Then you can print it out on the page where it is easy to read.

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

The topic ‘Image Field Return URL not Working’ is closed to new replies.