March 23, 2010

Image Source from Sub Directory in WordPress

I’m not sure if it’s possible to declare a source path in the image tag by the root directory. The following code will not reference the desired image.

<img src="<?php echo TEMPLATEPATH; ?>/images/logo.png" />

WordPress seems to call all their files starting from the http:// protocol. Normally, I would say it’s good practice to call images and files relative from you current directory. But in this case, I can’t seem to find a way to reference images from my sub-directories without hard-coding in the path. Unless someone knows a better way, I will continue using the hack below.

<img src="<?php bloginfo('template_directory'); ?>/images/logo.png" />
  1. Cool! This will save me a ton of time! Wish I could have found this sooner…

    Comment by Angie Wennerlind — April 3, 2010 @ 10:34 am

Leave a comment