Created
February 21, 2023 15:35
-
-
Save tomaskavalek/c3344d24ee99cbc55e27ce031a98dc0c to your computer and use it in GitHub Desktop.
WordPress – Add user roles to body class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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