7.x path.inc current_path()

Return the current URL path of the page being viewed.


This function is not available in hook_boot() so use $_GET['q'] instead. However, be careful when doing that because in the case of Example #3 $_GET['q'] will contain "path/alias". If "node/306" is needed, calling drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) makes this function available.

Return value

The current Drupal URL path. The path is untrusted user input and must be treated as such.

See also


15 calls to current_path()
common_test_init in modules/simpletest/tests/common_test.module
Implements hook_init().
drupal_cache_system_paths in includes/path.inc
Cache system paths for a page.
drupal_goto in includes/common.inc
Sends the user to a different page.
drupal_lookup_path in includes/path.inc
Given an alias, return its Drupal system URL if one exists. Given a Drupal system URL return one of its aliases if such a one exists. Otherwise, return FALSE.
drupal_redirect_form in includes/form.inc
Redirects the user to a URL after a form has been processed.

... See full list


includes/path.inc, line 355
Functions to handle paths in Drupal, including path aliasing.


function current_path() {
  return $_GET['q'];


ñull’s picture

Will also return URLs without the language prefix.

loopduplicate’s picture

and here's how to get the alias:

$path = current_path();
$path_alias = drupal_lookup_path('alias',$path);

reference: http://api.drupal.org/api/drupal/includes%21path.inc/function/drupal_loo...

blazindrop’s picture

request_path() already gives you the *current* alias in use - see http://api.drupal.org/api/drupal/includes!bootstrap.inc/function/request...

drupal_lookup_path() is helpful when you want to lookup aliases for pages other than the current page.

guy_schneerson’s picture

not the same thing if you are on a localized site with language codes in url

print drupal_get_path_alias(current_path());  // will print "some_url"

print request_path();  // will print "en/some_url"

Using request_path() can lead to problems in conditional code and doubling up of the language code i.e 'en/en/' in some cases.

martini9011’s picture

Note that when using drupal_get_path_alias() you don't have to pass the current_path() function. Calling drupal_get_path_alias() as is will get the alias for the current page.

pal4life’s picture

This was very helpful.

matt2000’s picture

$GLOBALS['base_url'] => http://example.com/drupal
base_path() => /drupal/
request_uri() => /drupal/documentation?page=1
request_path() => documentation
current_path() => node/26419

sodu.parsiev’s picture

$GLOBALS['base_url'] => http://example.com

Dane Powell’s picture

Note that current_path() has been removed in Drupal 8, and doesn't have a direct replacement. See this issue for details: