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!

  • Take a careful read of the answers and comments on the pages you linked to, and look at the dates. Some are quite old, and plausibly no longer work. But there are also newer answers, and comments, which sound like worth following. Apr 2, 2019 at 4:18

1 Answer 1


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' );
  • Oh wow, I didn't realize that hook existed!! Thank you @phatskat
    – nickpish
    Apr 2, 2019 at 4:13
  • 1
    No problem! The easiest way to start finding the hooks and actions you need is to open the file - in this case, I opened /wp-login.php and searched for <body, and found the filter a few lines above. Never touch core, but don't be afraid to look around ;)
    – phatskat
    Apr 2, 2019 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.