Sometimes you may want to style or hide and element if a user is logged out, you can achieve this by adding a custom body tag that will load only when a user is logged out.
// Add custom boddy class when user is logged out
function add_body_logged_out($classes) {
if (! ( is_user_logged_in() ) ) {
$classes[] = 'logged-out';
}
return $classes;
}
add_filter('body_class','add_body_logged_out');
– LAST TESTED DECEMBER 9, 2019
Code not working? Let us know in the comments below.