1

I'm new to WordPress. My question is,

Now default user forgot password redirecting to website/wp-login.php?action=lostpassword&redirect_to=http%3A%2F%2website.com%2Fuser-profile

But I have a custom page /password-reset/. So I refer some post and added below code in my theme function.php

add_filter( 'lostpassword_url',  'my_lostpassword_url', 10, 0 );
function my_lostpassword_url() {
    return site_url('/password-reset/');
}

But it's not working. So I added rewrite rule in .htaccess file - as first line

RewriteRule ^wp-login.php?action=lostpassword$ website.com/password-reset/ [R=301,L]

Both are not working. Any solution for this?

0

I see what you're trying to do, but it appears you only "ALMOST" followed the code example provided by the codex.

Below is an annotated version of their sample code, substituting your desired URL:

// You need the "10,2" in for WP to pass their parameters .. you can ignore them from that point forward.
// 10 = Priority. Ensures it takes precedence, replacing the default.
// 2 = Allows WP to pass two parameters.
add_filter( 'lostpassword_url', 'my_lostpassword_url', 10, 2 );
function my_lostpassword_url( $lostpassword_url, $redirect ) {
    // I recommend using the WP method, although you could use your return value        
    $redirect = '/password-reset/';
    // Your url would also work. I just like the redirector...
    return site_url( '/lostpassword/?redirect_to=' . $redirect );
}

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.