Site logo

Archived topic

Custom Classes on Elements Layout

3 replies · Started by Matt on December 2, 2020

Viewing posts 1–4 of 4

Hi Guys,

I'm using the 'Elements' module to create 2 layouts.. 1 for logged in users, one for logged out users. I'm wondering if there is any way to apply a custom class to these layouts (preferably on the body tag) so that I can do some syling based on each layout?

Thanks.

How would I make this conditionally apply to one of the 2 layouts created in elements? I don't want the same class on all body tags.
Thanks

You can add in "if" conditions depending.

Example:

add_filter( 'body_class', function( $classes ) {
    if(is_user_logged_in()){
        return array_merge( $classes, array( 'your-class-name' ) );
    } else {
        return $classes;
    }
} );

What this snippet does is, it checks if the current visitor is logged in. If the visitor is logged in, it adds a custom class. Else(meaning non logged in visitors), it will display the default classes.

This archived topic is closed to new replies.