Created
March 18, 2014 18:05
-
-
Save bryanmonzon/9625824 to your computer and use it in GitHub Desktop.
Output the image URL of an ACF field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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