I am having a code to show images, but if no image available need to show default image
Currently, I am having this code
<?php ?>
<img src="<?php echo get_the_post_thumbnail_url($post->ID); ?>"/>
<?php ?>
I am having a code to show images, but if no image available need to show default image
Currently, I am having this code
<?php ?>
<img src="<?php echo get_the_post_thumbnail_url($post->ID); ?>"/>
<?php ?>
Use has_post_thumbnail()
method to check the post have thumbnail and based on that provide default image.
<?php if (has_post_thumbnail()) : ?>
<img src="<?php echo get_the_post_thumbnail_url($post->ID); ?>"/>
<?php else: ?>
<!-- default image here -->
<?php endif; ?>
You can use ternary operator to reduce the code.
<img src="<?php echo (has_post_thumbnail() ? get_the_post_thumbnail_url($post->ID) : 'default_image.jpg'); ?>"/>