WordPress lostpassword_errors Filter

Written by
Published
Updated
Typical Read
1 minutes

Unlike the registration_errors filter, there's not a lostpassword_errors filter... but there is another filter you can use instead!

I spent a couple of hours of searching and another one debugging attempting to find a WordPress filter for errors like the:

ERROR: Invalid username of email.

that appears on the lost password page. Since there’s a registration_errors filter, I thought lostpassword_errors or something close to it would be available. Nope.

/**
 * Used to modify the error messages that are displayed above the login form.
 */
function hook_login_errors( $error ) {
  return $error;
}
add_filter( 'login_errors', 'hook_login_errors' );

Turns out it uses the login_errors filter, cause you know… that makes sense. So, why would you ever need this?

Simple answer. In my particular case, I’m overriding all WordPress registration, login and lost passwords pages. I needed a way to redirect users to my custom lost password page when the lost password form is submitted and errors were found.

Hope this help other WordPress devs out there that have been spending hours searching for the same thing I did. If you have another way, comment below, I’d love to read about it!

1 comment on “WordPress lostpassword_errors Filter”.

Carlos

# Jun 16, 2018

Heeey great!
I’ve been looking for information about this and I did not have anything until now, thank you very much for the help

Sorry for my English! I try to make an effort

Join the conversation.

Your email address will not be published. Required fields are marked *

All comments posted on 'WordPress lostpassword_errors Filter' are held for moderation and only published when on topic and not rude. Get a gold star if you actually read & follow these rules.

You may write comments in Markdown. This is the best way to post any code, inline like `<div>this</div>` or multiline blocks within triple backtick fences (```) with double new lines before and after.

Want to tell me something privately, like pointing out a typo or stuff like that? Contact Me.