echo out image variable in conditional statement

Im trying to display an image in a conditional statement.

Without the condition I can simply do:

Read More
<div>
    <img src="<?php echo($img); ?>" />
</div>

But lets say that i have condition like this:

<?php
    if ($img ) {
       echo "image exists";

        // Show image

        } else {
        echo "no image..";

        }
?>

I am using wordpress and the $imgcontains a url.
Help appreciated. Thank you!

Related posts

Leave a Reply

2 comments

  1. Try:

    <?php if !empty($img) { // check if $img not empty ?>
     <div> <!-- display image -->
        <img src="<?php echo($img); ?>" />
     </div>
    <?php } else { // if $img empty 'no image' show message 
            echo "no image..";
          }
    ?>