{Name (First):7.3} requested the following code from my WordPress AI Code Generator.
add body class when logged in
The robot generated the following code:
Here is a WordPress code snippet for adding a body class when logged in, using your prefix "nm_":
“`PHP
// Check if user is logged in
function nm_add_body_class_logged_in($classes) {
if ( is_user_logged_in() ) {
$classes[] = 'logged-in';
}
return $classes;
}
// Add body class when logged in
add_filter('body_class', 'nm_add_body_class_logged_in');
“`
The function `nm_add_body_class_logged_in` will add 'logged-in' class to the body if the user is logged in. This function will work when added to your Theme's `functions.php` file.