Using WordPress ‘lostpassword_form’ PHP action

The lostpassword_form WordPress action fires inside the lost password form tags, before the hidden fields.

Usage

add_action('lostpassword_form', 'your_custom_function');
function your_custom_function() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: lostpassword_form

Examples

Add a custom message to the lost password form

This example adds a custom message to the lost password form.

add_action('lostpassword_form', 'add_custom_message_to_lost_password_form');
function add_custom_message_to_lost_password_form() {
    echo '**Note**: Check your spam folder for the password reset email.';
}

Add a security question to the lost password form

This example adds a security question to the lost password form for additional security.

add_action('lostpassword_form', 'add_security_question_to_lost_password_form');
function add_security_question_to_lost_password_form() {
    echo '<label for="security_question">What is your favorite color?</label>';
    echo '<input type="text" name="security_question" id="security_question" required>';
}

Add a reCAPTCHA to the lost password form

This example adds a reCAPTCHA to the lost password form to prevent bots from submitting the form.

add_action('lostpassword_form', 'add_recaptcha_to_lost_password_form');
function add_recaptcha_to_lost_password_form() {
    echo '<div class="g-recaptcha" data-sitekey="your-recaptcha-site-key"></div>';
}

Add a custom CSS class to the lost password form

This example adds a custom CSS class to the lost password form for styling purposes.

add_action('lostpassword_form', 'add_custom_class_to_lost_password_form');
function add_custom_class_to_lost_password_form() {
    echo '<style>.custom-lost-password { background-color: #f1f1f1; padding: 20px; }</style>';
    echo '<script>document.getElementById("lostpasswordform").classList.add("custom-lost-password");</script>';
}

This example adds a link to a page with more information about account security to the lost password form.

add_action('lostpassword_form', 'add_link_to_lost_password_form');
function add_link_to_lost_password_form() {
    echo '<p><a href="/account-security-tips">Read our account security tips</a></p>';
}