drupal_get_path_alias

5 path.inc drupal_get_path_alias($path)
6 path.inc drupal_get_path_alias($path, $path_language = '')
7 path.inc drupal_get_path_alias($path = NULL, $path_language = NULL)
8 path.inc drupal_get_path_alias($path = NULL, $langcode = NULL)

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()

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

The complementary function is drupal_get_normal_path().

Does drupal_get_path_alias filter input?

For 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.

The $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

Borrowed 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

Or you could just use Pathauto.

Login or register to post comments