login_form
Fires after the login form is displayed on the WordPress site.
add_action( 'login_form', $callback, 10, 1 );
Description
Fires within the login form structure, after potential 2FA checks but before the default WordPress login form is rendered. Developers can use this hook to add custom fields, modify existing elements, or inject additional content directly into the login form template.
Usage
add_action( 'login_form', 'your_function_name', 10, 1 );
Examples
// Add a custom field to the WordPress login form for a "remember me" checkbox
add_action( 'login_form', 'my_custom_remember_me_login_field' );
/**
* Adds a custom "Remember Me" checkbox to the WordPress login form.
*
* @since 1.0.0
*/
function my_custom_remember_me_login_field() {
// Retrieve the current value of the 'rememberme' cookie if it exists.
$checked = ( isset( $_COOKIE['rememberme'] ) && $_COOKIE['rememberme'] == 'forever' ) ? 'checked="checked"' : '';
?>
<p class="login-remember">
<label>
<input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php echo $checked; ?> /> <?php esc_html_e( 'Remember Me', 'my-text-domain' ); ?>
</label>
</p>
<?php
}
// Note: The 'login_form' hook does not accept any parameters, so the accepted_args count is 0.
// This is an action hook, so no return statement is needed within the callback function.
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/templates/frontend-login/default-login.php:44
src/templates/frontend-login/layout_1-login.php:195
src/templates/frontend-login/modern_ui-login.php:202
</p>
<?php }
if ( uo_toolkit_2fa_form_exists() ) {
uo_toolkit_2fa_render_authentication_form();
} else {
do_action( 'login_form' );
wp_login_form( $login_form_args );
}
// Add registration link allowed
if ( get_option( 'users_can_register' ) ) {
$show_register = Config::get_settings_value( 'uo_frontend_show_register_link', 'FrontendLoginPlus' );
if ( 'on' === $show_register ) {