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.

8

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

Example:

$link = url('taxonomy/term/1');
| improve this answer | |
  • drupal_get_path_alias('taxonomy/term/[id]') will also work. – Jonathan Bergeron Aug 2 '16 at 20:29
1

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'

| improve this answer | |
  • Useful knowing about the leading slash! Thank you! – Natalie Apr 9 '19 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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