Change class by log in status with Thesis
While I was re-styling the display of my comments, I wanted to be able to differentiate whether a user was logged in to WordPress or not. I didn’t want to muck around with Thesis’ PHP code and potentially break a future upgrade, so I used a WordPress filter to add class="logged_in"
or class="logged_out"
to the <body>
tag.
function add_login_body_classes($classes) {
if (is_user_logged_in()) {
$classes[] .= 'logged_in';
} else {
$classes[] .= 'logged_out';
}
return $classes;
}
add_filter('thesis_body_classes', 'add_login_body_classes');
Add this to your Thesis’ custom_functions.php
file.
The code is seriously simple. The add_login_body_classes
function takes the existing classes Thesis was going to add to <body>
and adds either logged_in
or logged_out
depending on the user’s status. The add_filter
function adds it to the WordPress filter processor to get processed.