What else does body_class() do other than generate some standard route level CSS classes?

Is it okay to omit if your'e using something like Tailwind? I used to rely on it basically for namespacing, but I don't tend to write CSS like that anymore. Does it do anything else? Is it crucial for a functioning theme?

3 Comments
  1. Yay themes inject all sorts of stuff through there. Don’t remove it :). I would say it’s pretty important as you can get classes for when you are on the home page, single page, archives, posts, etc. it really helps with styling knowing what class of page you are on.

  2. Sounds like you are building a custom site for your own purposes, if that’s the case totally fine to ignore it and use whatever works for you.

    If you are building a theme for public distribution, you should keep it because people using the theme would expect it potentially and it doesn’t really hurt anything.

  3. It’s irrelevant if you’re making your own theme. If you have plugins that generate frontend code, however, it might matter if A) they rely on the default classes, or B) they’re adding their own classes through the [`body_class`](https://developer.wordpress.org/reference/hooks/body_class/) filter. If B is at play, then you may just want to filter out what you don’t want yourself.

    (You can also use [`get_body_class()`](https://developer.wordpress.org/reference/functions/get_body_class/) to retrieve the filtered classes without echoing.)

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer