WordPress wp_lostpassword_url() Function

Definition
In WordPress, wp_lostpassword_url() returns the URL of the lost password page, where users can ask for a password reset email.
It is useful for a custom login form. Add a "Forgot your password?" link next to it.
Syntax
It returns a string, so wrap it in esc_url().
<?php
echo esc_url( wp_lostpassword_url() );
| Call | What it does |
|---|
wp_lostpassword_url() | The lost password page address. |
wp_lostpassword_url( home_url() ) | Go to the home page after the reset. |
wp_lostpassword_url( get_permalink() ) | Return to this page afterwards. |
The page it points to is part of the normal login screen.
Full declaration
wp_lostpassword_url( string $redirect = '' ): string
Parameters
| Parameter | Description |
|---|
$redirect | string. The page to open after the reset. Default is empty. |
Return Value
| Return Value | Description |
|---|
| string | The lost password URL, with redirect_to when you pass one. |
WordPress Examples
Three short theme examples. Each one shows the code and what it prints.
Example 1 — A "Forgot password?" link
Place it under a login form.
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>">
Forgot your password?
</a>
<a href="https://example.com/wp-login.php?action=lostpassword">
Forgot your password?
</a>
How It Works
wp_lostpassword_url() returns the page address.esc_url() keeps it safe.- The link opens the reset form.
Example 2 — With a redirect
Send users to the home page afterwards.
<?php echo esc_url( wp_lostpassword_url( home_url() ) ); ?>
https://example.com/wp-login.php?action=lostpassword&redirect_to=https%3A%2F%2Fexample.com
How It Works
- The first argument is the next page.
- It is added as
redirect_to. - Use it when you build your own flow.
Example 3 — Next to a login form
Show the form and the link together.
<?php if ( ! is_user_logged_in() ) : ?>
<?php wp_login_form(); ?>
<p><a href="<?php echo esc_url( wp_lostpassword_url() ); ?>">Lost password?</a></p>
<?php endif; ?>
<form name="loginform" ...>...</form>
<p><a href="https://example.com/wp-login.php?action=lostpassword">Lost password?</a></p>
How It Works
- Guests see the login form.
- Under it we add the reset link.
- Logged-in users see neither.
Frequently Asked Questions
It returns the URL of the lost password page as a string.
No. It only returns the URL. Write the link tag yourself.
It sets the page to open after the reset is finished.
No. Add the link yourself with wp_lostpassword_url().
Next: wp_meta()
Run the wp_meta action so plugins can add items to the Meta list.
wp_meta() tutorial →About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
10 people found this page helpful