Created
August 29, 2023 03:33
-
-
Save gdnwebmedia/ecf9d05ef225778ccd6aca05ca8d27bc to your computer and use it in GitHub Desktop.
Add current user role to the 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 | |
add_filter( 'body_class', 'add_role_to_body_class' ); | |
function add_role_to_body_class( $classes ) { | |
// Get the current user's roles | |
$user_roles = wp_get_current_user()->roles; | |
// Loop through the roles and add them to the body class | |
foreach ($user_roles as $role) { | |
$classes[] = $role . '-role'; | |
} | |
// Return the modified classes | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment