Skip to main content
Login Join
Snippet · PHP

ACF Image Field Fallback to Featured Image

Shared by Akshar Makwana · August 22, 2026

6 views
1 upvote
Back to Snippets

This snippet displays an ACF image field when an image is available. If the ACF image field is empty, it automatically falls back to the post’s Featured Image.

This is useful for WordPress listings, blog cards, custom post types, and archive templates where you want to give priority to a custom ACF image while keeping the Featured Image as a fallback.

The example below assumes that the ACF image field returns an image array.

<?php
// Get the ACF image field.
$acf_image = get_field( 'listing_page_image' );

if ( ! empty( $acf_image ) && ! empty( $acf_image['url'] ) ) {
    echo '<img src="' . esc_url( $acf_image['url'] ) . '" alt="' . esc_attr( $acf_image['alt'] ) . '">';
} elseif ( has_post_thumbnail() ) {
    the_post_thumbnail(
        'full',
        [
            'loading'  => 'lazy',
            'decoding' => 'async',
        ]
    );
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments