WordPress Body Class 101: Tips and Tricks for Theme Designers

What is WordPress Body Class?

Body Class (body_class) is a WordPress function that gives the body element different classes, so theme authors can style their sites effectively with CSS. HTML body tag is present in mostly your header.php file which loads on every page. When coding a theme, you can attach the body_class function to your body element like so:

<body <?php body_class($class); ?>>

By adding this little element, you give yourself the flexibility of easily modifying the look of each page by using CSS. Depending on the type of page being loaded, WordPress automatically adds the appropriate class. For example, if you are on an archive page, WordPress will automatically add archive class to the body element if you choose to use it. It does that for just about every page…

via WordPress Body Class 101: Tips and Tricks for Theme Designers.

Published by

Suzette Franck

Suzette Franck has been in web development for over twenty years; she started making hand-coded HTML websites on geocities with font tags and tables back in 1995. Since then, she has taught herself CSS, Sass, PHP, MySQL, as well as becoming a Wordpress expert; evangelizing and presenting at over twenty-two WordCamps across the country and multiple WordPress meetups in Southern California where she resides, about all aspects of building and maintaining sites on WordPress.

Suzette is passionate about WordPress the application as well as the WordPress Open Source Community, and loves to code and teach others the wonders of WordPress. She is a purveyor of lowbrow art, and when she is not WordPressing, she is painting or visiting Los Angeles art galleries to add more work to her growing art collection.

What do you think?