0

I am trying to display what might be called a placeholder image if an image custom field has not been provided

I've got this far but am a bit stuck. The output is showing the code. Here is the PHP I am using.

$my_image = get_post_meta($post->ID, 'ecpt_images', true);

if( isset($my_image) && $my_image != '') {
    echo '<img src="'.$my_image.'" width="230px" height="175px" />';
} else { 
    echo '<img src="/wp-content/uploads/2013/02/Poor.png">';
}

Thank you very much in advance

4
  • 2
    Are you sure that you're surrounding your PHP code with <?php /* code */ ?>? Commented Feb 12, 2013 at 20:12
  • 1
    please clarify what you mean by The output is showing code Commented Feb 12, 2013 at 20:13
  • Try rewriting if statement like if strlen ($myimg) > 0 , assuming image path is correct and it exists Commented Feb 12, 2013 at 20:24
  • The better way IMO is to have a container element with a css background image (which will be hidden if there is an actual image). This might even help with your problem (like iight I do not fully understand what the problem actially is). Commented Feb 12, 2013 at 20:24

1 Answer 1

1

Check if you used short open tag <? /* your code */ ?>. This setting is by default disabled and not recommended. Make sure you wrapped your code properly within <?php /* your code */ ?>.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.