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.

I have the following code but I always get an error, it's the first time I've tried to merge HTML with PHP:

<?php
if(get_field('post_image'))
{
    echo '<img src="'. get_field('post_image') .'" />';
}
else {
    echo '<img src="<?php bloginfo('template_url'); ?>/images/images/default.jpg" />';
}
?>

Is there something wrong the blog info area? Is there an easier way to integrate these?

Thanks

share|improve this question
    
Mark right answer –  Eugene Manuilov Apr 12 '12 at 10:06
    
Plain PHP syntax questions are on topic on Stack Overflow. –  toscho Apr 12 '12 at 10:21
    
Perhaps, but it's harder to tell what the problem is when it could be related to the code WP provides and the way I've used it, though easier to tell once it's solved –  Phill Apr 12 '12 at 11:00
add comment

closed as off topic by toscho Apr 12 '12 at 10:21

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 1 down vote accepted

You get the error because you try to call php inside php. Try to use this snippet and see what is different:

<?php
if(get_field('post_image'))
{
    echo '<img src="'. get_field('post_image') .'" />';
}
else {
    echo '<img src="' . get_bloginfo('template_url') . '/images/images/default.jpg" />';
}
?>

Also pay attention that bloginfo immediately prints value, when get_bloginfo returns it.

share|improve this answer
    
Apart from the second 'images' in the URL, this worked brilliantly. So a single quote and some concatenation solve this in all instances? Thank you –  Phill Apr 12 '12 at 10:03
    
I've added comments to my answer –  Eugene Manuilov Apr 12 '12 at 10:05
add comment

bloginfo() echo's its result you need get_bloginfo()
Also the Else echo is just wrong

the else should be:

echo '<img src="'.get_bloginfo('template_url').'/images/images/default.jpg" />';
share|improve this answer
    
Still get an error even with that: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\sites\kennedy\wp-content\themes\kennedy\side-home.php on line 19 –  Phill Apr 12 '12 at 10:01
    
read my update. You did it right in the first echo –  janw Apr 12 '12 at 10:03
add comment

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