Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress The WordPress Template Hierarchy Archive Templates in WordPress Category Archives

Carl Sergile
Carl Sergile
16,570 Points

In regards to the body class...

Can you name the class anything, just as you would if you were styling html with CSS or do you have to give the body a class in relations to the file name?

ex. body class="this_body_class" .this_body_class { color: blue; }

** picture the greater/less than sign around the body.

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,956 Points

If I'm understanding your question correctly, body class isn't the same as a HTML class that you can target with CSS as such. It's a PHP function used in WordPress to add various setting to a website. To get to it, you'd simply add it like this

<body <?php body_class(); ?>>.

I don't quite know how it works but aparently it lets you add CSS styling to individual pages. Here's a little bit of info about the things you can do with it. :) http://wpshout.com/body_class/

Carl Sergile
Carl Sergile
16,570 Points

Okay this is a really good read. Like really good. So it pretty much helps you customize elements on the page depending on their id. What stops you from adding different classes to anything? I feel like with the example in the link you can then add this to the wp_header maybe? Since you are using add_filter(); ? Is this somewhat correct?