I'm working on a theme index.php and it seems that when I use the "template_directory" it is not actually pulling the url path of the file, but instead is just pulling the main domain name. So instead of


its pulling the domain url and showing this


I don't understand why it's doing this, since the index.php file is actually in the right directory. (which is inside the theme folder). There is the index.php file that is in the wordpress directory... but I don't understand why it would conflict with the themes index.php file.

  • 1
    Can you post the actual code you're using? Otherwise, it will be nearly impossible to help you. – Chip Bennett Sep 30 '11 at 20:51

To get the exact path of image which is placed in http://example.com/wp-content/themes/theme_name/images/pic.jpg in your theme.

All you have to use below code:

  1. To show image
<img src="<?php bloginfo('template_url'); ?>/images/pic.jpg" />
| improve this answer | |
  • The bloginfo() template tag already echoes its result; you don't need to echo it explicitly. bloginfo() echoes its result, while get_bloginfo() returns its result. Also, I strongly recommend using get_template_directory_uri() in place of get_bloginfo( 'template_url' ). – Chip Bennett Oct 3 '11 at 12:58

I suspect one of two things:

  1. You're not using the correct template tag.

    Are you using get_template_directory_uri() or something else?

  2. You're not echoing the result

    If you're using get_template_directory_uri(), you have to echo it; e.g. this:


Will result in:

<a href="/images/pic.jpg">Link</a>

So, you need to do this:

<a href="<?php echo get_template_directory_uri(); ?>/images/pic.jpg">Link</a>

Which will result in:

<a href="http://www.example.com/wp-content/themes/theme-name/images/pic.jpg">Link</a>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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