Support

Account

Home Forums Front-end Issues Unable to get images to display

Solving

Unable to get images to display

  • Hello,

    I have created a field group with some fields, including an image field where I can upload an image.

    I am trying to get the image to be a background to a div.

    I have looked at several examples on this site to get images to display and none of them seem to work, so I am not sure what I am missing.

    My code:

    <div class="game-hero-image" style="background-image:url('<?php the_field('hero_image'); ?>');"></div>

    This is from this example: https://www.advancedcustomfields.com/resources/image/

    <?php if( get_field('image') ): ?>
        <img src="<?php the_field('image'); ?>" />
    <?php endif; ?>

    Since the the_field(‘image’) is in the src=”” attribute I would assume that this would return the full url of the image but it returns this:

    background-image: url('208, 208, Godfall_PS5_HI, Godfall_PS5_HI.jpg, 47117, http://localhost/wordpress/wp-content/uploads/2020/04/Godfall_PS5_HI.jpg, http://localhost/wordpress/games/godfall/attachment/godfall_ps5_hi/, , 1, , , godfall_ps5_hi, inherit, 206, 2020-04-23 12:55:42, 2020-04-23 12:55:42, 0, image/jpeg, image, jpeg, http://localhost/wordpress/wp-includes/images/media/default.png, 1920, 360, Array');

    As you can see the URL of the imatge is in there but the rest is not needed, is there a simple way to display the image url for use in <img src=”” or background-image:url(”)

    I also tried the example which gets the image ID and is like <?php echo$image[0]; ?>, the exact code I use to display post images as background images but for some reason the ACF just displays an empty string for the example.

    Any help woudl be greatly appreciated.

    Thanks.

  • Check your setting for return value of your image field.

  • Thanks,

    I had return value set as array, changed to url now working perfect.

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

The topic ‘Unable to get images to display’ is closed to new replies.