View Full Version : WordPress Headache...

08-24-2008, 08:50 PM
Why is it that this: <?php bloginfo('template_directory'); ?>, will work for things like stylesheets, but I can't make it work for an image?

<img src="<?php bloginfo('template_directory'); ?>/images/blah.jpg">

08-24-2008, 11:04 PM
did you rename your /images/ directory after installing wordpress? the default directory is /img/, not /images/. that may be your problem.

08-24-2008, 11:45 PM
no, the directory for images inside my theme directory is "images" not "img"

08-25-2008, 07:38 AM
I'm not sure how to answer your specific wordpress question but if you can't figure it out, in your template where you are trying to use images you might be able to hardcode it with something like the following...

<?php $TEMPLATE_PATH = $_SERVER[DOCUMENT_ROOT] . '/wp-content/themes/YOUR_THEME/images/'; ?>

That can be added to the top of your page so if your path ever changes you only have to change it once in your page. You could also in theory place just that in a page named "wp_temp_path.php" or something similar. If you are working with other pages you could include that path page to use it in the same way across many pages.

Where you want to place an image, you should be able to do something like this...

<img src="<?php echo "{$TEMPLATE_PATH}blah.jpg"; ?>">

That way if you know your image is in the images folder, you can just add it like above and php should do the rest for you.

I can understand that wordpress is what you are working with so you would like to figure it out, but if no one else has any suggestions the above might work for what you are trying to do. Hope that helps.

08-26-2008, 01:18 AM
After you do that, view the source and look at the output. Does it link to the correct image path?