Last active
February 27, 2023 11:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?