I would like to customize the messages for one time login links (i.e. password reset links). In some cases, I redirect the user to the login page. In these cases, it does not make sense to have "Please request a new one using the form below."

Is there a hook or module I can use to add some logic to that message? (I can do a global override with String Overrides, but am looking for more conditional messages.)

I am using Drupal 7.

  • Drupal version? – sanzante Mar 21 '17 at 22:21
  • Whoops, Drupal 7. Edited. – MrPeanut Mar 21 '17 at 22:22

If you mean the email message for a password reset. You can use hook_mail_alter to change the email contents before it's sent out to the user.

If you mean the form the user sees on the webpage, then you can use hook_form_alter to change the verbiage shown on the screen.


override the displayed form with the reset button to goto your own form_submit action. In your custom module action, simply copy and paste user_pass_reset function body into your own function and tweak it as needed to change the messages (careful).

| improve this answer | |
  • I actually mean the messages that are shown when a link is clicked. Specifically, drupal_set_message(t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'), 'error'); in user_pass_reset. – MrPeanut Mar 21 '17 at 22:52
  • see my edit to my answer. – tenken Mar 21 '17 at 22:57
  • Then he should alter the reset link menu, not the form. The user_pass_reset is a menu callback. – sanzante Mar 21 '17 at 23:32
  • Ops, sorry, you are right, it's form. I always use the link with the /login at the end and forgot is managed by a form not a direct link. – sanzante Mar 21 '17 at 23:56
  • Would something like this work? ignoredbydinosaurs.com/posts/… – MrPeanut Mar 22 '17 at 19:56

Those messages are pretty harcoded in user module in the file user.pages.inc, user_pass_reset function.

There's no hook to alter drupal set messages, but if you want to suppress certain messages you have luck with the module Disable Messages:

Gives a site owner options to disable specific messages shown to end users.


  • Filter out messages that match a full text string exactly.
  • Filter out messages that match a regular expression.
  • Permissions to specifically hide all messages of a given type from any role.
  • Disable all filtering for specific users.
  • Disable all filtering for specific paths.
  • Apply filtering only for specific paths.
  • Debug system to get messages in the HTML without showing it to the end users.

About using rules

There is an issue about this: Is it possible to unset or override system messages with Rules?

| improve this answer | |
  • If I disable them, is there a way (either programatically or via Rules) to set a new message? I was looking for a Rule event for "One time login link was clicked" or something, but did not find any. (Other modules offer Rules integration but do not play well with Password Reset Landing Page, which I also use.) – MrPeanut Mar 21 '17 at 22:56
  • Not possible with rules at the moment, answer updated. – sanzante Mar 21 '17 at 23:08

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.