2

I am writing a module, and am confused about the term's URLs. because, if pathauto moduel is installed, then the alias of that module should be provided. How to achieve this?

Default drupal's URL: taxonomy/term/30 Pathauto's probable pattern:

category/30
category/[title]
category/[title]/[id]
...and millions of other possible patte

Using drupal_get_path_alias() returns drupal's default path.

How should I get the path used by pathauto? I have seen pathauto's module, but it does not provide an API for this purpose as it seems.

2 Answers 2

10

Just use the url() function. It will return aliased path if you have pathauto installed.

Example:

$link = url('taxonomy/term/1');
1
  • drupal_get_path_alias('taxonomy/term/[id]') will also work. Aug 2, 2016 at 20:29
2

You can either use url() or drupal_get_path_alias() but make sure that your path argument doesn't have leading slash.

Example:

drupal_get_path_alias('/taxonomy/term/1');
url('/taxonomy/term/1');

Returns path '/taxonomy/term/1'

drupal_get_path_alias('taxonomy/term/1');

Returns 'tags/some-tag'

url('taxonomy/term/1');

Returns '/tags/some-tag'

1
  • Useful knowing about the leading slash! Thank you!
    – Natalie
    Apr 9, 2019 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.