Using WordPress ‘login_form_middle’ PHP filter

login_form_middle is a WordPress PHP filter that allows you to add custom content in the middle of the login form, right after the ‘login-password’ field.

Usage

add_filter('login_form_middle', 'your_custom_function', 10, 2);

function your_custom_function($content, $args) {
    // your custom code here
    return $content;
}

Parameters

  • $content (string): The content to display. Default is an empty string.
  • $args (array): An array of login form arguments.

More information

See WordPress Developer Resources: login_form_middle

Examples

Add a “Remember Me” checkbox

Add a “Remember Me” checkbox to the login form.

add_filter('login_form_middle', 'add_remember_me_checkbox', 10, 2);

function add_remember_me_checkbox($content, $args) {
    $content .= '<p class="rememberme"><label><input name="rememberme" type="checkbox" value="forever"> Remember Me</label></p>';
    return $content;
}

Add a custom message

Display a custom message in the middle of the login form.

add_filter('login_form_middle', 'add_custom_message', 10, 2);

function add_custom_message($content, $args) {
    $content .= '<p class="message">Welcome! Please log in to access your account.</p>';
    return $content;
}

Add a link to the privacy policy page in the login form.

add_filter('login_form_middle', 'add_privacy_policy_link', 10, 2);

function add_privacy_policy_link($content, $args) {
    $content .= '<p class="privacy-policy"><a href="/privacy-policy">Privacy Policy</a></p>';
    return $content;
}

Insert a “Lost your password?” link in the middle of the login form.

add_filter('login_form_middle', 'add_lost_password_link', 10, 2);

function add_lost_password_link($content, $args) {
    $content .= '<p class="lost-password"><a href="' . wp_lostpassword_url() . '">Lost your password?</a></p>';
    return $content;
}

Display a custom image

Add a custom image in the middle of the login form.

add_filter('login_form_middle', 'add_custom_image', 10, 2);
function add_custom_image($content, $args) {
    $content .= '<div class="custom-image"><img src="/path/to/your/image.png" alt="Custom Image"></div>';
    return $content;
}