I have edited the page.tpl.php file to include an image in the header and another in the footer of the page.

When I am in the home page of the site ie. '/product_range' the images are there. If I navigate to another part of the site ie. '/node/1' they are missing. Coincidently this is actually the same page just referenced differently in the url.

In the page.tpl.php template I have referenced the image like this:

<img src="<?php global $base_path; print path_to_theme(); ?>/images/brand_icons.gif" alt="" />

This is the actual path to the images: '\sites\all\themes\MySubTheme\images'

This is most frustrating... Thank you in advance for your assistance.


The return path from path_to_theme() doesn't have a slash at the front of it and so becomes relative to the path you're currently at. That would probably explain why it works for pages in the root of your site, but not those that are at least one directory down.

You should be able to fix it easily by adding a forward slash to the start of the image path:

<img src="/<?php print path_to_theme(); ?>/images/brand_icons.gif" alt="" />

On another note, make sure you fill the alt in...people with screenreaders will thank you for it :)

| improve this answer | |
  • Thank you for your quick response Clive. This worked and fixed my problem. – Terence Dec 11 '12 at 10:34
  • I noticed you didn't include the 'global $base_path;' in your solution. Why is that? – Terence Dec 11 '12 at 10:35
  • 1
    You weren't using it so it seemed redundant...you only need to import a global variable if you're explicitly making use of it within the current scope of code. – Clive Dec 11 '12 at 10:40
  • Is there a way to get the path to the site files directory? – Terence Dec 11 '12 at 11:00
  • Sorry I should probably made mention that I am using Drupal 7. – Terence Dec 11 '12 at 11:02

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.