Skip to content

Instantly share code, notes, and snippets.

@LeMiira
Created October 7, 2021 04:13
Show Gist options
  • Save LeMiira/18dad2dd7d2576c3c5980ca86bdcdff3 to your computer and use it in GitHub Desktop.
Save LeMiira/18dad2dd7d2576c3c5980ca86bdcdff3 to your computer and use it in GitHub Desktop.
add user role and login state to body class wordpress
add_filter('body_class','add_role_to_body');
function add_role_to_body($classes) {
$current_user = new WP_User(get_current_user_id());
$user_role = array_shift($current_user->roles);
$classes[] = 'role-'. $user_role;
$classes[] = !is_user_logged_in() ? 'not-logged-in' : '' ;
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment