Skip to main content

Get the current theme name in drupal with PHP and $theme_key

Today I was working on a mobile theme for a client of ours and I needed to remove the printer friendly link from every page. The first thing I did was create a hook_link_alter() function in my custom module and quickly realized this would alter every theme.

I came across this article (http://drupal.org/node/46961) that lead me to the $theme_key variable. Using this I quickly limited my hook_link_alter function to the proper theme. The final function looks like this:


function HOOK_link_alter(&$links, $node, $comment = NULL) {
global $theme_key;
if ($theme_key == 'MY_CURRENT_THEME') {
// Remove the printer friendly page from the mobile theme.
unset($links['print_html']);
}

}


Comments