Drupal

Get the Current NID and Node for a Page in Drupal 7

Anywhere in code, if you want the current NID or Node for that page – if it exists – use this

$nid = (arg(0) == 'node' && is_numeric(arg(1))) ? arg(1) : NULL;

To load the current node, then is

if (!empty($nid)) {
   $node = node_load($nid);
}

Leave a Reply