Question

I can't figure out for the life of me how to add a custom body class to the WordPress login page. I found this thread, which suggests using the admin_body_class along with this one to check if the current page is the login, and nothing seems to work. I have a multisite network going, and my ultimate aim is to add the blog_id number for each site to its corresponding login page as a body class- is this possible? This is one approach I've tried, to no avail:

function login_body_class($classes) {     
    global $blog_id;

    if ( $GLOBALS['pagenow'] === 'wp-login.php' ) {
        $append = ' ' . $blog_id . ' ';
        $classes .= $append;
    }
    return $classes;
}

add_filter('admin_body_class', 'login_body_class');

(Given that admin_body_class takes a string and not an array, I've added in spaces before/after the class name.) Thanks for any insight here!

Was it helpful?

Solution

I think you're on the right track with a filter. Have you tried login_body_class as the filter?

function add_blog_id_to_login_page( $classes ) {
    $blog_id   = get_current_blog_id();
    $classes[] = "blog-{$blog_id}";
    return $classes;
}

add_filter( 'login_body_class', 'add_blog_id_to_login_page' );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top