如果您正在寻找将角色添加到body class, 就像这里:
<body class=" ... role-administrator role-jedi role-knight ... ">
然后您可以尝试以下操作:
add_filter( \'body_class\', function( $classes )
{
if( is_user_logged_in() )
{
$classes = array_merge(
(array) $classes,
array_map(
function( $class )
{
return \'role-\' . $class; // Here we prepend the \'role-\' string
},
(array) wp_get_current_user()->roles
)
);
}
return $classes;
} );