最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Change lost password url to a mailto URL in Wordpress

programmeradmin4浏览0评论

can you help me, how can I change the lost password link to an email action with specified subject? I found that in the functions.php I can add a new filter like this:

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

But I dont know how can I implement the mailto action instead of the new url. Can you help me?

can you help me, how can I change the lost password link to an email action with specified subject? I found that in the functions.php I can add a new filter like this:

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

But I dont know how can I implement the mailto action instead of the new url. Can you help me?

Share Improve this question edited Sep 22, 2020 at 11:51 Tom J Nowell 61k7 gold badges79 silver badges148 bronze badges asked Sep 22, 2020 at 11:38 BlackdogBlackdog 31 bronze badge 6
  • A mailto action is just a URL that starts with mailto: instead of http: or https:, the specifics of how a mailto URL is formatted or built though isn't a WordPress problem but a general HTML question – Tom J Nowell Commented Sep 22, 2020 at 11:50
  • a quick google of "mailto url" gives this and a tonne of others lifewire/how-to-create-a-mailto-link-3466469, <a href="mailto:[email protected]">Send me an email</a> – Tom J Nowell Commented Sep 22, 2020 at 11:51
  • :-) I know what is a mailto action, but my question was how can I implement into the code, what I wrote above. Please listen to my question before giving an unnecessarily wrong answer. Thank you! – Blackdog Commented Sep 22, 2020 at 13:37
  • These aren't answers, they're comments, answers will appear underneath with voting controls and their own comments. Note that any answer you get will require basic programming knowledge, it won't be a copy paste solution. Can you expand on what's missing that you don't understand or have? Is the code above code that you wrote? How familiar are you with filters – Tom J Nowell Commented Sep 22, 2020 at 14:08
  • So, I have a webpage, where I'd like to control the lost passwords. I disabled earlier the reset password option under WP. I searched and found an answer in this forum, where somebody want the change the default lost password page url. This is the code about I wrote. I don't want another page with another url for lost password, but if somebody lost his password then write me an e-mail with subject lost password. If I write it in a html page then it is a simple <a href="mailto:[email protected]?subject=Mail from Our Site">Email Us</a> – Blackdog Commented Sep 22, 2020 at 17:37
 |  Show 1 more comment

1 Answer 1

Reset to default 0

This answer assumes you're running PHP 5.3 or above.

Use the filter code below in-place of your code that you quoted above. Then simply update the variables provided so that it's sending to the correct email address and with the particular subject you'd like.

add_filter( 'lostpassword_url', function () {
    $email_to = '[email protected]';
    $email_subject =  'Help I lost my password';
    return sprintf( 'mailto:%s?subject=%s', $email_to, $email_subject );
}, 100, 0 );

Note: You cannot change the anchor text "Lost Password" that is used in the link.

发布评论

评论列表(0)

  1. 暂无评论