| 7 path.inc | drupal_get_path_alias($path = NULL, |
| 4.6 bootstrap.inc | drupal_get_path_alias($path) |
| 4.7 path.inc | drupal_get_path_alias($path) |
| 5 path.inc | drupal_get_path_alias($path) |
| 6 path.inc | drupal_get_path_alias($path, $path_language = '') |
Given an internal Drupal path, return the alias set by the administrator.
Parameters
$path: An internal Drupal path.
$path_language: An optional language code to look up the path in.
Return value
An aliased path if one was found, or the original path if no alias was found.
4 calls to drupal_get_path_alias()
- block_list in modules/
block/ block.module - Return all blocks in the specified region for the current user.
- path_nodeapi in modules/
path/ path.module - Implementation of hook_nodeapi().
- url in includes/
common.inc - Generates an internal or external URL.
- _statistics_link in modules/
statistics/ statistics.module - It is possible to adjust the width of columns generated by the statistics module.
File
- includes/
path.inc, line 108 - Functions to handle paths in Drupal, including path aliasing.
Code
function drupal_get_path_alias($path, $path_language = '') {
$result = $path;
if ($alias = drupal_lookup_path('alias', $path, $path_language)) {
$result = $alias;
}
return $result;
}
Comments
Complements
PermalinkThe complementary function is drupal_get_normal_path().
Does drupal_get_path_alias filter input?
PermalinkFor example, if you used it like this:
$path = drupal_get_path_alias($_GET['q']);Is that safe? Or should the $_GET be wrapped in check_plain() or another security function?
Do not worry about the arguments, only worry about the output.
PermalinkThe $path variable in this case must be properly escaped either with check_plain() or check_url() depending on how it is being output.
Converting to clean seo friendly paths
PermalinkBorrowed from this node:
Adding external files through drupal API: http://drupal.org/node/225868
Added to template.php:
<?php/*
* Globe Runner SEO = GRS
* Use your own namespace if you'd like!
*
* @return String - Provides you with a clean url
*/ function grs_get_path() {
return strtolower( preg_replace( '/[^a-zA-Z0-9-]+/', '-', drupal_get_path_alias( $_GET['q'] ) ) );
}
?>
Or you could just use
PermalinkOr you could just use Pathauto.