WordPress lostpassword_errors Filter

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!

Comments

  1. 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

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

All comments are held for moderation and only published when on topic and not rude. You'll even get little stars if you do an extra good job.

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.

icon-search icon-link