EDIT: I've found out that this question doesn't make sense. The problem isn't that the hook is not called during the bulk_update. The problem is that the code generates unexpected aliases because of the "variable_set" request, which led me to think that the hook wasn't called. See my answer for the correct code to programmatically set alias patterns.

I have created a function to alter the alias for a particular content type when certain conditions are met, using the following code:

function HOOK_pathauto_alias_alter(&$alias, array &$context) {

       variable_set('pathauto_node_contentype_pattern', 'something/[node:title]');

The problem is, when I create a node and save it, it works, but when i try to bulk update the aliases, it doesn't, and the default pattern set from the GUI is used instead.

3 Answers 3


Issue can be with the setting for Url aliases, when you run the bulk update. You need to keep it on the " Create a new alias. Delete the old alias. ". SO it will run update your old aliases. Please check if it works for you.

enter image description here

  • hmmm not really, I'm looking for a way to make Pathauto use my custom function when bulk-generating aliases.
    – Sifro
    Jul 5, 2014 at 8:07

Works as designed (see edited issue summary).

If you need to alter patterns like me, here's what Pathauto's writer said:

Setting variables in a hook like this is a bad idea, and not to mention, happens too late for it to actually affect the alias being generated. There is an actual hook for you to use instead, you should use that one instead of the alias alter hook.

 * Alter the pattern to be used before an alias is generated by Pathauto.
 * @param string $pattern
 *   The alias pattern for Pathauto to pass to token_replace() to generate the
 *   URL alias.
 * @param array $context
 *   An associative array of additional options, with the following elements:
 *   - 'module': The module or entity type being aliased.
 *   - 'op': A string with the operation being performed on the object being
 *     aliased. Can be either 'insert', 'update', 'return', or 'bulkupdate'.
 *   - 'source': A string of the source path for the alias (e.g. 'node/1').
 *   - 'data': An array of keyed objects to pass to token_replace().
 *   - 'type': The sub-type or bundle of the object being aliased.
 *   - 'language': A string of the language code for the alias (e.g. 'en').
 *     This can be altered by reference.
function hook_pathauto_pattern_alter(&$pattern, array &$context) {
  // Switch out any [node:created:*] tokens with [node:updated:*] on update.
  if ($module == 'node' && ($context['op'] == 'update')) {
    $pattern = preg_replace('/\[node:created(\:[^]]*)?\]/', '[node:updated$1]', $pattern);
  • Nice! Change $module to $context['module'] and you should be good to go.
    – ola
    May 25, 2021 at 6:18

As Sifro said use hook_pathauto_pattern_alter or there is an another way if you want to have custom data in url patterns. Create a token. For me the best way was to use Variables, make it as a token and i18n aware

 * Implements hook_variable_info().
function custom_variable_info($options) {

  $variables['support_pattern'] = array(
    'type' => 'text',
    'title' => t('Support Pathauto Variable', array(), $options),
    'description' => t('Variable for custom pathauto variable for taxonomy, "support" vocabulary', array(), $options),
    'required' => TRUE,
    'localize' => TRUE,
    'token' => TRUE, // We'll produce tokens automatically for this on
  return $variables;

Your Answer

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

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