Hide Broken Images

Hi, how could I hide the thumbnail image when there is none present like on this page? http://highendlaptops.net/category/computers/ (scroll to the bottom of page to see them missing )

The php code I have looks like this:

<?php $screen = get_post_meta($post->ID, 'screen', $single = true); ?>
<img src="<?php echo ($screen); ?>" width="250" height="120" alt=""  />

I would like something like “if image is not available then don’t try to display image…”

that’s perfect, thanks a lot!

Out of courtesy for Salathe, please find an amended, 1-typo-less example.


<?php $screen = get_post_meta($post->ID, 'screen', $single = true); ?>
<?php if(false === empty($screen)) printf('<img src="&#37;s" width="250" height="120" alt="#" />', $screen) ; ?>

Thanks Salathe, I think. :stuck_out_tongue:

@Anthony, except without the typo (:

Off Topic:

When Anthony edits his post to fix the mistake, this post will sure look out of place.

This should do it.


<?php $screen = get_post_meta($post->ID, 'screen', $single = true); ?>
<?php if(false === empty($screen) printf('<img src="&#37;s" width="250" height="120" alt="#" />', $screen) ; ?>