Hi, I would like to execute some code if the user is viewing a node. but I need the node to be being viewed at the url node/[nid], but not to be executed if the node gets viewed in a view.

Thanks for any help

Comments

jaypan’s picture

if(preg_match('/^node\/\d+$/', $_GET['q']))
{
  // you are on the node page
}

Contact me to contract me for D7 -> D10/11 migrations.

nevets’s picture

You can also use

$node = menu_get_object();
if ( !empty($node) ) {
  // On the node page
}