The login_body_class WordPress PHP Filter allows you to modify the body classes of the WordPress login page.
Usage
add_filter('login_body_class', 'your_custom_function', 10, 2);
function your_custom_function($classes, $action) {
// Your custom code here
return $classes;
}
Parameters
- $classes (string[]): An array of body classes currently assigned to the login page.
- $action (string): The action that brought the visitor to the login page.
More information
See WordPress Developer Resources: login_body_class
Examples
Add a custom class to the login page body
Add the ‘my-custom-class’ class to the login page body classes.
add_filter('login_body_class', 'add_custom_class', 10, 2);
function add_custom_class($classes, $action) {
$classes[] = 'my-custom-class';
return $classes;
}
Remove a specific class from the login page body
Remove the ‘login’ class from the login page body classes.
add_filter('login_body_class', 'remove_login_class', 10, 2);
function remove_login_class($classes, $action) {
$classes = array_diff($classes, array('login'));
return $classes;
}
Add different classes based on the action
Add different classes to the login page body based on the action (login, logout, lost password, etc.).
add_filter('login_body_class', 'add_action_based_class', 10, 2);
function add_action_based_class($classes, $action) {
$classes[] = 'action-' . $action;
return $classes;
}
Add a class to the login page body based on the user agent
Add a ‘mobile’ class to the login page body if the user is visiting from a mobile device.
add_filter('login_body_class', 'add_mobile_class', 10, 2);
function add_mobile_class($classes, $action) {
if (wp_is_mobile()) {
$classes[] = 'mobile';
}
return $classes;
}
Add a class based on the current day
Add a class to the login page body based on the current day of the week (e.g. ‘monday’, ‘tuesday’, etc.).
add_filter('login_body_class', 'add_day_based_class', 10, 2);
function add_day_based_class($classes, $action) {
$current_day = strtolower(date('l'));
$classes[] = $current_day;
return $classes;
}