如果图像在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'); ?>"/>  

Try this,

if (file_exists('current_file_path')) {
  <img src="current_file_path"/> 
}else{
  <img src="path_to_default_image"/> 
}