Hi,
// Add current user role to the front end page body element
add_action('wp_head', 'add_current_user_role_class');
function add_current_user_role_class() {
if ( is_admin() ) {
// do not show at back-end
return;
}
if ( !is_user_logged_in() ) {
return;
}
$user = wp_get_current_user();
$user_roles = array_values( $user->roles );
$role = array_shift( $user_roles );
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
var body = document.body;
body.classList.add('<?php echo $role; ?>');
});
</script>
<?php
}
Wow
Amazing!
To display on the backend is possible?
I deleted this part of the code and it seems that still does not work on the backend
if ( is_admin() ) {
// do not show at back-end
return;
}
Thx 4ever!
-
This reply was modified 4 years, 8 months ago by
ofmarconi.
-
This reply was modified 4 years, 8 months ago by
ofmarconi.