By default when a user is logged in, a 'logged-in' classname is appended to the body tag. I need to append something like 'guest-user' to the body to output different styling based on whether or not the user is logged in.
How can I achieve this? Something maybe I could put in my child theme's functions.php file?
Thanks.
By default when a user is logged in, a 'logged-in' classname is appended to the body tag. I need to append something like 'guest-user' to the body to output different styling based on whether or not the user is logged in.
How can I achieve this? Something maybe I could put in my child theme's functions.php file?
Thanks.
Share Improve this question asked Sep 24, 2019 at 14:36 JosephJoseph 31 bronze badge1 Answer
Reset to default 1Yes, there's the body_class filter. You could use e.g.
function body_class_guest_user( $classes, $class ) {
if ( ! is_user_logged_in() ) {
$classes[] = 'guest-user';
}
return $classes;
}
add_filter( 'body_class', 'body_class_guest_user', 10, 2 );
However you could equally well just use the :not() selector, e.g. body:not(.logged-in)
(browser support),
or absence of logged-in i.e. set up the guest-user styling as default but then override it if .logged-in
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745133772a4613101.html
评论列表(0条)