search ]

Add Logged-In Body Class on Frontend

WordPress adds logged-in to the body when a user is logged in, but only in the admin. The following code adds a class on the frontend too. Useful for custom styling or showing different content. For more on WordPress hooks and filters.

add_filter( 'body_class', function( $classes ) {
	if ( is_user_logged_in() ) {
		$classes[] = 'logged-in-user';
	}
	return $classes;
} );
Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo