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.

Trying to do some dynamic image sourcing but I'm stuck. Probably pretty basic stuff, but I'm new to this.

This works:

<img src="<?php  bloginfo('template_url');?>/images/LakeArnaulMap-<?php the_ID();?>.png"/>

Why doesnt this:

<?php 
$my_img = '<img src="' . bloginfo('template_url') . '/images/MyImage' . the_ID() . '.png"/>';
echo $my_img;
?>
share|improve this question
    
Please read the codex documentation for the_ID() codex.wordpress.org/Function_Reference/the_ID –  Chris_O Feb 11 '13 at 18:34
2  
Use get_bloginfo() and get_the_ID() to return the result instead of print it. –  Max Yudin Feb 11 '13 at 18:34
    
The Codex is your friend ;) –  brasofilo Feb 11 '13 at 19:09
add comment

1 Answer 1

bloginfo echoes the output in place. If you look at the source you will see that template_url is not where you expect it to be.

Use get_bloginfo instead, or even better use get_stylesheet_directory

share|improve this answer
    
Thank you kindly! –  user27314 Feb 11 '13 at 18:41
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.