Skip to main content

Getting a path to your subtheme

File under

Was working with a subtheme today and ran into a problem with theme_get_path(), which is supposed to return the path to the active theme (actually, it's slightly more complicated than that; the value you get back depends on the context in which you call it).

Unfortunately, theme_get_path() does not always work correctly for subthemes. Instead of getting the path to your subtheme, you might get the path to the parent theme. In Drupal 5.x, I suppose you could have put up with it, since subthemes had to be in subfolders of their parent themes. Drupal 6.x has no such requirement (which is a good thing), but it means you need another method.

This worked for me :

global $theme_key;
$path_to_theme = drupal_get_path('theme', $theme_key);

Put that in one of your theme's preprocess functions, depending on where you need to access the theme path. In my case, I put it into theme_preprocess_node().

Hat tip to Michelle Cox for posting a similar solution.