• Resolved PRuddyArt

    (@pruddyart)


    Evening,

    I’m new to ACF and have started to implement it on my TwentyFifteen child theme which uses a Custom Post Type for a gallery of artwork. The other fields I have tried have worked as expected but I’m having trouble with the most important one for this task – images.

    I’ve tried two methods from the documentation.

    1. From Displaying Values in your theme

    <img src="<?php the_field('art'); ?>"/>
    Which displays a broken image symbol and shows this in the source code:
    <img src="286, , Prowl into the Spotlight, , , image/jpeg, http://www.pamelaruddy.co.uk/pr_wp/wp-content/uploads/2015/08/IMG_1341.jpg, 1031, 825, Array"/>
    Which seems to be an array of all the data to do with the image.

    And
    2. From ‘Code Examples’

    <?php $artworkimage = wp_get_attachment_image_src(get_field('art'), 'full'); ?>
    <img src="<?php echo $artworkimage[0]; ?>" alt="<?php echo get_the_title(get_field('artworkimage')) ?>" />

    Which just displays an empty SRC with the alt tag:
    <img src="" alt="Prowl into the Spotlight" />

    The image does display in the admin section when I’ve uploaded it. And the URL displayed within the array does link to the image, so it is there. As the other custom fields from the group do work, I’m sure I’ve added it to the correct template.

    Obviously the info is there, I’m just not sure how to pull the right bit into the SRC part of the image tag.

    This is the page (custom post type ‘artwork’) I’m experimenting with, I’ve take off the ‘Coming soon’ plugin specially for you so don’t expect it to be pretty or anywhere near finished.

    Thanks

    https://wordpress.org/plugins/advanced-custom-fields/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter PRuddyArt

    (@pruddyart)

    Would help if I’d put the link in!

    An example artwork page

    Thread Starter PRuddyArt

    (@pruddyart)

    I eventually found this page in the documentation via a search ACF – images

    I used the basic display

    <?php 
    
    $image = get_field('image');
    
    if( !empty($image) ): ?>
    
    	<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    
    <?php endif; ?>

    Which has worked. I’m still unsure as to why the other methods failed in my case, and if they don’t work well generally, then maybe making this method more prominent in the documentation might be useful.

    I wasn’t able to view the page which I found via a google search when I was working earlier in the day as the site was down, and I forgot I had that tab open till now.

    I’ll probably put my website back onto coming soon, but hope anyone with a similar problem finds the link to the image page of the documentation useful.

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘ACF functions for IMG not linking to image’ is closed to new replies.