Returns an html 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.

$attr: (array) Array of attributes to add to the html image markup.

$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( $acf_image = '', $post_id = 0, $size = 'post-thumbnail', $attr = '', $use_thumbnail_as_fallback = false ) {

	if ( ! $post_id ) {
		global $post;
		$post_id = $post->ID;

	//if were trying to get the header image, and the user specified not to, then return none.
	if ( $size == 'header_image' && get_field( 'no_image', $post_id ) ) {
		return '';

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

	return $image;