I have this code and im using Advanced Custom Fields. Its inside Post Type and i need to show images even if Field doesnt have Link. How can i show image even when Field doesnt have Link?
<div >
<?php
$link = get_field('link_product');
if( $link ):
$link_url = $link['url'];
?>
<a target="_blank" href="<?php echo esc_url( $link_url ); ?>">
<img src="<?php echo the_post_thumbnail_url();?>" alt="">
</a>
<?php endif;
?>
</div>
CodePudding user response:
Currently the image is inside the if and when link is false the code is skipped.
You can simple add the else condition before the endif and put the image there.
<?php
else:
?>
<img src="<?php echo the_post_thumbnail_url();?>" alt="">
<?php
endif;
?>