add class to body if user is logged in

WordPress AI Code Robot

Create WordPress code snippets for free without a developer!

{Name (First):7.3} requested the  following code from my WordPress AI Code Generator.

add class to body if user is logged in

The robot generated the following code:

Here is a WordPress code snippet to prefix all functions with `nm_add` and include a class in the body if a user is logged.

“`php
function nm_add_body_class_if_logged_in( $classes ) {
// Check if user is logged in.
if ( is_user_logged_in() ) {
// Add 'logged-in' class to the $classes array if user is logged in.
$classes[] = 'logged-in';
}

// Return the array.
return $classes;
}
add_filter( 'body_class', 'nm_add_body_class_if_logged_in');
“`

More
CODE SNIPPETS