I know I can load a node by its title with the node_load() function. Is it possible to load a node by its URL alias?


You want to investigate menu_get_object and drupal_lookup_path.

Something like this would do what you want:

$alias = "some/path/to/a/page";
$path = drupal_lookup_path("source", $alias);
$node = menu_get_object("node", 1, $path);
  • Also, to dynamically grab url alias do next: $alias = $_SERVER['REQUEST_URI']; $alias = substr($alias, 1); // to remove "/" from beginning of string – Eugene Pavlov Jul 21 '16 at 20:55
  • @EugenePavlov - $alias = drupal_get_path_alias(); should be it. – leymannx Apr 5 '17 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.