Struggling to show image with ACF WordPress

Viewed 21

I've been trying to display an image with ACF code and have just got it working, but I can't work out why some code works and some doesn't.

if(get_row_layout() == 'bq_product'):
        $image = the_sub_field('affiliate_image');
        $affiliate_url = the_sub_field('affiliate_url');
                
        
        ?><img src="<?php echo $image ?>"/><?php //This line doesn't work and just displays the raw URL on the front end
        ?><img src="<?php the_sub_field('affiliate_image') ?>"/><?php //This line works and shows the image
        ?><a href="<?php $affiliate_url ?>">Link</a> //Similarly, this line doesn't use the URL set in affiliate_url, but does if I pass "the_sub_field('affiliate_url')"

How do I use the variable names within the image src without it just showing the raw URL on the front end?

I've tried using "get_sub_field" variations but they don't seem to make a difference.

0 Answers
Related