WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This should be simple, and yet everything I'm trying blows the blog up.

I want to be able to specify an image variable in a custom field (that works great) but if that's not specified, don't include the image code. It's creating a image missing error in some browsers (IE).

Any ideas?

Thanks, Bob

share|improve this question
would help if we could see your code. – Milo Aug 24 '11 at 20:38
I'm trying to, but can't return or it posts my comment. – Bob Aug 24 '11 at 20:40
What I have now is this to grab the variable and create the image tag: <img width="600" src="<?php $postimage="postimage"; echo get_post_meta($post->ID, $postimage, true); ?>"> I've tried isdefined, isset to see if $postimage exists, but can't get this correct. – Bob Aug 24 '11 at 20:42

you just have to check if it exists before outputting any markup.

$postimage = get_post_meta($post->ID, 'postimage', true);
    <img src="<?php echo $postimage; ?>" />
share|improve this answer
Thanks so much for your help. I was dancing all around it, but this did the trick. I appreciate you taking the time to help. Bob – Bob Aug 24 '11 at 21:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.