0

Hi all this is wordpress php question I am trying to get thumbnail from custom field image. Please help me with the code thank you so much.

<?php
if (get_post_meta($post->ID, 'thumbnail', true)) {
echo "<img src='echo get_post_meta($post->ID, 'thumbnail', true)' width='100px' />";
}else{
echo "<img src='http://site.com/default.jpg' width='50px' />";
}   
?>

Above code results default pic where custom field image is not added but is giving out img code shown below as output for custom filled image.

<img src='echo get_post_meta(86, ''thumbnail'', true)' width='100px' />

1 Answer 1

1

The problem most likely is that you have an echo statement inside another echo statement.

<?php
if (get_post_meta($post->ID, 'thumbnail', true)) {
echo "<img src='" . get_post_meta($post->ID, 'thumbnail', true) . "' width='100px' />";
}else{
echo "<img src='http://site.com/default.jpg' width='50px' />";
}   
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Ya works thanks a lot. I knew it was problem with quotes in echo statement, just didn't know how to fix it :) Thanks again

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.