Community Documentation

path_to_theme

5 theme.inc path_to_theme()
6 theme.inc path_to_theme()
7 theme.inc path_to_theme()
8 theme.inc path_to_theme()

Return the path to the current themed element.

It can point to the active theme or the module handling a themed implementation. For example, when invoked within the scope of a theming call it will depend on where the theming function is handled. If implemented from a module, it will point to the module. If implemented from the active theme, it will point to the active theme. When called outside the scope of a theming call, it will always point to the active theme.

▾ 4 functions call path_to_theme()

bartik_preprocess_html in themes/bartik/template.php
Add body classes if certain regions have content.
garland_preprocess_html in themes/garland/template.php
Override or insert variables into the html template.
seven_preprocess_html in themes/seven/template.php
Override or insert variables into the html template.
template_preprocess in includes/theme.inc
Adds a default set of helper variables for variable processors and templates. This comes in before any other preprocess function which makes it possible to be used in default theme implementations (non-overridden theme functions).

File

includes/theme.inc, line 1105
The theme system, which controls the output of Drupal.

Code

<?php
function path_to_theme() {
  global $theme_path;

  if (!isset($theme_path)) {
    drupal_theme_initialize();
  }

  return $theme_path;
}
?>

Comments

To unconditionally get the path to your theme…

…and not the themed element, use:

<?php
  drupal_get_path
('theme', 'THEME_NAME');
?>

The path returned with path_to_theme() depends on where and when it's called which can be hard to predict. It's usually fine in most cases but if you're getting unpredictable results use drupal_get_path().

thanks!

I was calling path_to_theme in block--system--main.tpl.php and for some reason it was giving me garland (I was sub-theming garland). drupal_get_path works much better.

Frontend theme

if you use different theme for the admin area you get that theme instead...

So, is there any way to get the path,or at least,the name of the current frontend theme and not the administration one?

To get the current front-end (default) theme

Try this:

$theme_path = drupal_get_path('theme', variable_get('theme_default', NULL));

It should return the path to the default theme. Handy when you have different front-end and back-end themes.

Pete

Login or register to post comments