I'm adding a logo image to my page.tpl.php template this way:

<a class="mobile-brand" href="#"><img src="<?php print drupal_get_path("theme", "my_custom_theme"); ?>/img/logo-mobile.png"></a>

The image is being displayed fine in the homepage, but if I go to the /user page, for instance, the image won't show up.

Any ideas why is that happening?



Without a leading '/' (or '/foo/' if the site is in a subfolder) the browser will always to try to find the image relative to the current path, not to the root of the site. That's why your current code works on the home page, but not on other pages.

To fix it you just need to add the base path as well:

<a class="mobile-brand" href="#">
  <img src="<?php print $base_path . drupal_get_path("theme", "my_custom_theme"); ?>/img/logo-mobile.png">
| 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.