Get current page/url in a hook

stefgosselin picture stefgosselin · Mar 2, 2011 · Viewed 18.2k times · Source

In hook_css_alter, I want to disable style-sheets on specific pages. Was ok for the front page requirement with following snippet:

function morin_css_alter(&$css) {
  if(drupal_is_front_page()){
    foreach ($css as $data => $item) {
      unset($css[$data]);
    }
  }
}

Now I need to remove specific styles on a photo-album page. I have thought of a few ways to do this, but I'd like to do it the drupal way.

The closest function I have found to do this is drupal_get_destination() , I don't think it's meant for this but it does return the current path in an array, as shown by the following snippet added in css_alter hook.

echo " PATH = " . var_dump(drupal_get_destination());

Output: PATH = array(1) { ["destination"]=> string(6) "photos" }

Is this the recommended way of getting the path from inside a function/hook, or is there some variable in global namespace I should use instead?

Answer

Berdir picture Berdir · Mar 2, 2011