Skip to content

Instantly share code, notes, and snippets.

@bryanmonzon
Created March 18, 2014 18:05
Show Gist options
  • Save bryanmonzon/9625824 to your computer and use it in GitHub Desktop.
Save bryanmonzon/9625824 to your computer and use it in GitHub Desktop.
Output the image URL of an ACF field
/**
* This function is intended to help you grab an image uploaded with ACF.
*
* @param [string] $field The ACF field you want to grab content from
* @param [string] $size The size of the image (defaults to thumbnail)
* @param boolean $subfield If the field is in a repeater, you need to use get_sub_field()
* @uses get_field()
* @uses get_sub_field()
* @return [string] the URL of the image
*/
function imag_the_acf_image( $field = null, $size, $subfield = false )
{
global $post;
$size = isset( $size ) ? $size : 'thumbnail';
if( $subfield == false ){
$image = get_field( $field, $post->ID );
}else{
$image = get_sub_field( $field, $post->ID );
}
echo $image['sizes'][$size];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment