Answer the question
In order to leave comments, you need to log in
How to add class to body tag using php?
How to make it so that when entering the site {made on wordpress} with the choice of a specific role {subscriber, author}, a class with the value of the role is added to the body tag. For example, if you go to the site by selecting the subscriber role, then the subscriber class was added to the body tag?
Answer the question
In order to leave comments, you need to log in
function role_body_class($classes) {
if (is_user_logged_in()) {
$user_data = get_userdata(get_current_user_id());
$classes[] = $user_data->roles[0];
}
return $classes;
}
add_filter( 'body_class','role_body_class' );
<body class="<?=isset($class) ? $class : ''?>">
...
</body>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question