612-293-8629 [email protected]

WordPress has this nifty little “body_class()” function that I use every now and then to add css classes to the html “body” tag.

Today I wanted to add the current user’s id to the class, and here’s how I did it:

// Add user id CSS class via http://codex.wordpress.org/Function_Reference/body_class
add_filter( 'body_class', 'my_class_names' );
function my_class_names( $classes ) {
	// add 'class-name' to the $classes array
	global $current_user;
	$user_ID = $current_user->ID;
	$classes[] = 'user-id-' . $user_ID;
	// return the $classes array
	return $classes;

If a user is not logged in, they get the “user-id-0” class.

Pretty neat, eh?


We love to communicate: phone, email, text, Facebook, Twitter, LinkedIn, you name it.



Call Now

Enroll in Our Free Beginner WordPress Class by Email

Never feel powerless in WordPress again!  Become a WordPress superstar for free in only minutes a day!

Our Beginner WordPress Email Class is delivered to your inbox!

Learn More 

You Have Successfully Enrolled! Prepare For Amazing!