wp_lostpassword_url()
Returns the URL that allows the user to retrieve the lost password
Hooks from the function
Return
String
. Lost password URL.
Usage
wp_lostpassword_url( $redirect );
- $redirect(string)
- Path to redirect to on login.
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. |