WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

$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
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

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

Your Answer


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.