Within the context of a module, how can you determine what theme is loaded for the current user?
drupal_get_path
path_to_theme
Neither of these are any good because they seem to only work in the template.php of a theme.
Within the context of a module, how can you determine what theme is loaded for the current user?
drupal_get_path
path_to_theme
Neither of these are any good because they seem to only work in the template.php of a theme.
path_to_theme
should work just fine, I tested it on two Drupal installs, and both worked. If the theme has not been initialized yet, path_to_theme
will do that, which is what Drupal uses internally to set different global theme variables like $theme_path
, which is the variable you are looking for.
If users are allowed to select a theme for themselves, the theme they selected is saved in $user->theme
, where $user
is the user object.
The global variable $custom_theme
contains the name of the theme currently set, if a module has set a custom theme.
The following snippet saves in $current_theme
the name of the theme currently active:
global $custom_theme, $theme, $user;
if (!empty($user->theme)) {
$current_theme = $user->theme;
}
elseif (!empty($custom_theme)) {
$current_theme = $custom_theme;
}
else {
$current_theme = $theme ? $theme : variable_get('theme_default', 'garland');
}