Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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

<?php
$postimage = get_post_meta($post->ID, 'postimage', true);
if($postimage):
?>
    <img src="<?php echo $postimage; ?>" />
<?php
endif;
?>
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
add comment

Your Answer

 
discard

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.