Assuming that you’re in The Loop, you can fix this problem, by replacing:
1 2 3 |
if ( has_post_thumbnail() ) { // do a bunch of stuff } |
with
1 2 3 4 |
$featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) ); if ( ! empty( $featured_image_url ) ) { // do a bunch of stuff } |