Returns a url of an image from a ACF field. This is very good to use on advanced custom fields that are images. It will make sure to get the image properly so any filters and plugins will apply.


$acf_image: (array) The ACF image field gotten with get_field or get_sub_field on an image. The image should be set to array in the advanced custom field settings.

$post_id: (integer) The post_id for where to get the custom field. By default it is the current post.

$size: (string) WordPress Image size. By default it gets the post-thumbnail size.

$use_thumbnail_as_fallback: (boolean) If no image is found, it will output the featured image instead. This is set to false by default.

File: inc/template-tags.php

function ign_get_image_url( $acf_image = '', $post_id = 0, $size = '', $use_thumbnail_as_fallback = false ) {
	if ( ! $post_id ) {
		global $post;
		$post_id = $post->ID;

	$image = '';

	if ( $acf_image ) {
		$image_id = $acf_image['id'];
		$image    = wp_get_attachment_image_url( $image_id, $size, '' );
	} else {
		if ( has_post_thumbnail( $post_id ) && $use_thumbnail_as_fallback ) {
			$image = get_the_post_thumbnail_url( $post_id, $size );

	return $image;