Why does admin_body_class not work?
I'm trying to add the body class of the current user role to both the frontend and the admin backend.
Why does admin_body_class
not work for admin?
The comment to this question does not work: How to insert the current users role into the body class in the admin backend
This works for the front end in the theme's functions.php file:
add_filter(body_class, function($classes) {
global $current_user;
foreach ($current_user-roles as $user_role) {
$classes[] = role-{$user_role};
}
return $classes;
});
This does not work for the backend in the theme's functions.php file:
add_filter(admin_body_class, function($classes) {
$user = wp_get_current_user();
foreach ($user-roles as $user_role) {
$classes .= role-{$user_role};
}
return $classes;
});
Topic body-class user-roles filters Wordpress
Category Web