Skip to content

Instantly share code, notes, and snippets.

@tomaskavalek
Created February 21, 2023 15:35
Show Gist options
  • Save tomaskavalek/c3344d24ee99cbc55e27ce031a98dc0c to your computer and use it in GitHub Desktop.
Save tomaskavalek/c3344d24ee99cbc55e27ce031a98dc0c to your computer and use it in GitHub Desktop.
WordPress – Add user roles to body class
<?php
function tk_add_user_role_to_body_classes($classes)
{
global $current_user;
foreach ($current_user->roles as $user_role) {
if (is_admin()) {
$classes .= ' role-' . $user_role;
} else {
$classes[] = 'role-' . $user_role;
}
}
return $classes;
}
add_filter('body_class', 'tk_add_user_role_to_body_classes', 100);
add_filter('admin_body_class', 'tk_add_user_role_to_body_classes', 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment