0

I have category cars and I want to create its URL alias according to the region like if the user location is Australia than URL will mysite/australia/cars similar if the user location is USA than URL will be mysite/usa/cars.

Can you please anyone tell how can I achieve this kind of functionality?

Thanks in Advance.

  • You use pathauto module ? – berramou Nov 20 at 19:50
  • Yes, i am using pathauto @berramou – Adi Nov 20 at 20:11
  • Okay check my answer. – berramou Nov 20 at 20:42
0

If you use pathauto module:

You can use hook_pathauto_alias_alter like the following:

/**
 * Implements hook_pathauto_alias_alter().
 */
function YourModuleName_pathauto_alias_alter(&$alias, array &$context) {
  // Change tags here by your term name
  if ($context['module'] == 'taxonomy_term' && isset($context['type']) && $context['type'] == 'tags'){
   // Get the current user the location for example australia
    $user_location = 'australia';
    // Change the alias to be
    $alias = $user_location. '/cars/[term:name]';
  }
}
  • It will change permanent alias or something else? – Adi Nov 20 at 20:46
  • This hook fired on create and update of your taxomony terms – berramou Nov 20 at 20:48
  • From the hook comment section Alter Pathauto-generated aliases before saving – berramou Nov 20 at 20:50
  • But, I have already multiple terms than how I will use it for this? – Adi Nov 20 at 20:52
  • For already existing alias you should go to bulk generate admin/config/search/path/update_bulk and select terms pathauto will regenerate them for you . – berramou Nov 20 at 20:57

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.