Add a class to body in WP backend

// Add a class to <body> in backend with current user role
function print_user_class() {
	if ( is_user_logged_in() ) {
		add_filter('admin_body_class', 'class_to_body_admin');
	}
}
add_action('init', 'print_user_class');

function class_to_body_admin($classes) {
	global $current_user;
	$user_role = array_shift($current_user->roles);
	$classes = $classes . ' role-' . $user_role;
	return $classes;
}

Leave a Reply

Your email address will not be published.