I have the function below in a module. After it runs once, the token never changes again. I have to disable the module, and re-enable it, to get the token to run. Do you have any idea why this happens?

function my_token_values($type, $object = NULL, $options = array()) {
    global $user;

   $rand = rand();
   if ($type == 'global') {
        $tokens['random-number-replace'] = $rand;
   return $tokens;
  • Consider trying a cache clearing instruction? – Beanluc Jan 20 '12 at 11:23
  • How does one do that in the code? – kylex Jan 20 '12 at 16:12

Where are you using the token? Drupal may be caching information at a higher level (like the filtered output of a node, for example) and only calling the token generation code once.


This ended up being a completely unrelated issue, but what was happening is that the token was getting set once, and then somewhere a custom module was checking if the token was set before setting it again.

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.