Skip to content

Instantly share code, notes, and snippets.

@mclarenmervin
Created December 12, 2023 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mclarenmervin/300909d8b7266be2173eedc00ed977df to your computer and use it in GitHub Desktop.
Save mclarenmervin/300909d8b7266be2173eedc00ed977df to your computer and use it in GitHub Desktop.
ACF image url by image id
<?php
// first, get the image ID returned by ACF
$image_id = get_field('image_field');
// and the image size you want to return
$image_size = 'thumbnail';
// use wp_get_attachment_image_src to return an array containing the image
// we'll pass in the $image_id in the first parameter
// and the image size registered using add_image_size() in the second
$image_array = wp_get_attachment_image_src($image_id, $image_size);
// finally, extract and store the URL from $image_array
$image_url = $image_array[0];
?>
<img src="<?php echo $image_url; ?>" alt="">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment