wp_lostpassword_url()
Gets the URL (link) to the password recovery page. Commonly used in the template (template tag).
Hooks from the function
Returns
String.
Usage
$lostpassword_url = wp_lostpassword_url( $redirect ); echo esc_url( $lostpassword_url );
- $redirect(string)
URL to which the user will be redirected after they enter their email and click the password recovery button.
You can specify a URL only to pages of the current site.
If the field is left empty, the following link will be set: http://example.com/wp-login.php?checkemail=confirm
Default: ''
Examples
#1 Basic use:
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>">Forgot your password?</a>
Restore password with switching to the current page:
<a href="<?php echo esc_url( wp_lostpassword_url( get_permalink() ) ); ?>">Forgotten your password?</a>
Password recovery with switching to the home page:
<a href="<?php echo esc_url( wp_lostpassword_url( home_url() ) ); ?>">Forgotten your password?</a>
#2 Change the page for resetting the password with the hook
Let's say we created our password recovery page: /getpassword and now we need to change all the password recovery links on the site. This can be done quickly with the hook lostpassword_url:
add_filter( 'lostpassword_url', 'change_lostpassword_url', 10, 2 );
function change_lostpassword_url( $url, $redirect ){
$new_url = home_url( '/getpassword' );
return add_query_arg( array('redirect'=>$redirect), $new_url );
}
// Get it: http://example.com/getpassword?redirect=URL
Changelog
| Since 2.8.0 | Introduced. |