Using WordPress ‘lostpassword_redirect’ PHP filter

The lostpassword_redirect WordPress PHP Filter allows you to customize the URL users are redirected to after submitting the lost password/retrieve password form.

Usage

add_filter('lostpassword_redirect', 'your_custom_function');
function your_custom_function($lostpassword_redirect) {
    // your custom code here
    return $lostpassword_redirect;
}

Parameters

  • $lostpassword_redirect (string): The URL users will be redirected to after submitting the lost password form.

More information

See WordPress Developer Resources: lostpassword_redirect

Examples

Redirect to custom login page

Redirect users to a custom login page after they request a password reset.

add_filter('lostpassword_redirect', 'redirect_to_custom_login_page');
function redirect_to_custom_login_page($lostpassword_redirect) {
    $lostpassword_redirect = '/custom-login-page';
    return $lostpassword_redirect;
}

Redirect to homepage

Redirect users to the homepage after requesting a password reset.

add_filter('lostpassword_redirect', 'redirect_to_homepage');
function redirect_to_homepage($lostpassword_redirect) {
    $lostpassword_redirect = home_url();
    return $lostpassword_redirect;
}

Redirect to a thank you page

Redirect users to a thank you page after submitting the lost password form.

add_filter('lostpassword_redirect', 'redirect_to_thank_you_page');
function redirect_to_thank_you_page($lostpassword_redirect) {
    $lostpassword_redirect = '/thank-you';
    return $lostpassword_redirect;
}

Redirect based on user role

Redirect users to different pages based on their user role after submitting the lost password form.

add_filter('lostpassword_redirect', 'redirect_based_on_user_role', 10, 2);
function redirect_based_on_user_role($lostpassword_redirect, $user) {
    if (in_array('administrator', $user->roles)) {
        $lostpassword_redirect = '/admin-dashboard';
    } else {
        $lostpassword_redirect = '/user-dashboard';
    }
    return $lostpassword_redirect;
}

Redirect to a custom URL with a query parameter

Redirect users to a custom URL with a query parameter indicating a successful password reset request.

add_filter('lostpassword_redirect', 'redirect_to_custom_url_with_query');
function redirect_to_custom_url_with_query($lostpassword_redirect) {
    $lostpassword_redirect = '/custom-url?reset=success';
    return $lostpassword_redirect;
}