Skip to content

Instantly share code, notes, and snippets.

@posgross
posgross / wp-role-bodyclass.php
Created August 26, 2021 07:07 — forked from jancbeck/wp-role-bodyclass.php
WordPress: Add user role class to body tag
<?php
// Add role class to body
function add_role_to_body($classes) {
foreach (wp_get_current_user()->roles as $user_role) {
$classes[] = 'role-'. $user_role;
}
return $classes;
});
add_filter('body_class','add_role_to_body');