Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danielmcclure
Last active February 27, 2023 11:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmcclure/31463eb8c72316b21154f45483ad6777 to your computer and use it in GitHub Desktop.
Save danielmcclure/31463eb8c72316b21154f45483ad6777 to your computer and use it in GitHub Desktop.
Login Status body Class - Add Logged In/Out class to <body> with WordPress
<?php
/**
* Plugin Name: Login Status Body Class
* Plugin URI: https://gist.github.com/danielmcclure/31463eb8c72316b21154f45483ad6777
* Description: Adds logged-in or logged-out class to body tag depending on login status.
* Version: 1.0.0
* Author: danielmcclure
* Author URI: https://danielmcclure.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: login-status-class
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
//* Add Logged In/Out class to <body> with WordPress
add_filter( 'body_class', 'login_status_body_class' );
function login_status_body_class( $classes ) {
if (is_user_logged_in()) {
$classes[] = 'logged-in';
} else {
$classes[] = 'logged-out';
}
return $classes;
}
@applina
Copy link

applina commented Feb 10, 2023

hi! first of all thanks for your simple plugin...
somehow after activating the plugin the class logged-in is always on.
any idea to fix it?

@raftaar1191
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment