Get the URL of a Node or Term in Drupal 7

Given a Node or Taxonomy Term – or any “entity” based object

$uri = entity\_uri($entity\_type, $entity);
$url = $uri['path'];

When you create a link with the l() function, it will link to the Clean URL for that entity (if one exists).

for a Node

this becomes

$uri = entity_uri("node", $node);
$url = $uri['path'];

of course, you can always just use

$uri = node_uri("node", $node);
$url = $uri['path'];

or even

$url = "node/{$nid}"

for a Taxonomy Term

$uri = entity\_uri("taxonomy\_term", $term);
$url = $uri['path'];

of course, you can always just use

$uri = taxonomy\_term\_uri("node", $term);
$url = $uri['path'];

or even

$url = "taxonomy/term/{$tid}"

Leave a comment

Your email address will not be published. Required fields are marked *