Get Relative URL [Drupal]

How to get a theme-relative URL in Drupal. A wrapper function for Drupal (D6) to get a relative URL to a theme directory file; optionally specifying something other than your theme when called. Note – easiest to use if placed in template.php file, and manually replace MYTHEME with your theme name.

 * Get frontend-path to something, defaulting to theme-relative path
 * @param string $relativePath the path to the file (omit beginning slash), including filename, relative to whatever drupal path indicated
 * @param string $type defaults to 'theme' to retrieve relative to current theme directory
 * @param string $name default to the theme name, for use with interal call to drupal_get_path
function get_drupal_url($relativePath, $type = 'theme', $name = 'MYTHEME'){
      return sprintf('/%s/%s', drupal_get_path($type, $name), $relativePath);

Leave a Reply

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