Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoe Li
8,104 PointsWordpress, Advanced Custom Fields Image
Hey Guys,
I'm trying to pull an image from the advanced custom field plug in.
<?php the_field('image') ?> is pulling the full array.
How do I pull just the url?
Thanks,
Joe
2 Answers
mikes02
Courses Plus Student 16,968 PointsDid you check out their documentation? It's pretty straightforward:
<?php if( get_field('image') ): ?>
<img src="<?php the_field('image'); ?>" />
<?php endif; ?>
This assumes your field is named image and that you are using the URL return type. So for your settings on that field you would want the Return Value setting set to Image URL in order to use the example code above.
Joe Li
8,104 PointsThanks very much Mike! I had the return value set to Object!