Logged In and Logged Out Class Selector

Share this resource

Share on facebook
Share on twitter
Share on linkedin
Share on email
Share on facebook
Submitted by: Donald McGuinn

Add this code to your child theme functions.php file then use the class selectors below:

.loggedin

.loggedout

// LOGGED IN AND OUT BODY CLASS
// ============================================================================= 
// Add specific CSS class by filter
add_filter('body_class','er_logged_in_filter');
function er_logged_in_filter($classes) {
if( is_user_logged_in() ) {
$classes[] = 'loggedin';
} else {
$classes[] = 'loggedout';
}
// return the $classes array
return $classes;
}