我是WordPress的新手。我的问题是,
现在默认用户忘记密码重定向到website/wp-login.php?action=lostpassword&redirect_to=http%3A%2F%2website.com%2Fuser-profile
但我有一个自定义页面/password-reset/. 所以我参考了一些帖子,并在我的主题函数中添加了下面的代码。php
add_filter( \'lostpassword_url\', \'my_lostpassword_url\', 10, 0 );
function my_lostpassword_url() {
return site_url(\'/password-reset/\');
}
但它不起作用。所以我在中添加了重写规则。htaccess文件-作为第一行
RewriteRule ^wp-login.php?action=lostpassword$ website.com/password-reset/ [R=301,L]
两者都不起作用。有什么解决办法吗?
最合适的回答,由SO网友:Mike Baxter 整理而成
我知道你想做什么,但你似乎只是“几乎”遵循了codex提供的代码示例。
下面是示例代码的注释版本,替换了您所需的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 );
}
希望这有帮助!