The lostpassword_url WordPress PHP Filter allows you to modify the Lost Password URL.
Usage
add_filter('lostpassword_url', 'customize_lostpassword_url', 10, 2); function customize_lostpassword_url($lostpassword_url, $redirect) { // your custom code here return $lostpassword_url; }
Parameters
$lostpassword_url
(string) – The lost password page URL.$redirect
(string) – The path to redirect to on login.
More information
See WordPress Developer Resources: lostpassword_url
Examples
Change the Lost Password URL
Customize the lost password URL to a custom page.
add_filter('lostpassword_url', 'change_lostpassword_url', 10, 2); function change_lostpassword_url($lostpassword_url, $redirect) { $new_url = '/my-custom-lost-password-page'; return $new_url; }
Add a Redirect URL after Successful Reset
Redirect users to a specific page after a successful password reset.
add_filter('lostpassword_url', 'add_redirect_to_lostpassword_url', 10, 2); function add_redirect_to_lostpassword_url($lostpassword_url, $redirect) { $redirect_url = home_url('/password-reset-success'); return add_query_arg('redirect_to', urlencode($redirect_url), $lostpassword_url); }
Append a Custom Parameter to the Lost Password URL
Add a custom parameter to the lost password URL.
add_filter('lostpassword_url', 'append_custom_parameter', 10, 2); function append_custom_parameter($lostpassword_url, $redirect) { return add_query_arg('custom_parameter', 'value', $lostpassword_url); }
Change the Lost Password URL Based on User Role
Customize the lost password URL based on the user role.
add_filter('lostpassword_url', 'change_lostpassword_url_based_on_role', 10, 2); function change_lostpassword_url_based_on_role($lostpassword_url, $redirect) { if (current_user_can('subscriber')) { $new_url = '/subscriber-lost-password-page'; } else { $new_url = '/default-lost-password-page'; } return $new_url; }
Change the Lost Password URL for a Specific Page
Customize the lost password URL when users are on a specific page.
add_filter('lostpassword_url', 'change_lostpassword_url_for_page', 10, 2); function change_lostpassword_url_for_page($lostpassword_url, $redirect) { if (is_page('example-page')) { $new_url = '/custom-lost-password-page'; } else { $new_url = $lostpassword_url; } return $new_url; }