Skip to content

Instantly share code, notes, and snippets.

@gdnwebmedia
Created August 29, 2023 03:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gdnwebmedia/ecf9d05ef225778ccd6aca05ca8d27bc to your computer and use it in GitHub Desktop.
Add current user role to the body class
<?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