1

Does anyone know where I can get a list of all the body classes generated by body_class() for every sections and every conditions, including custom post-types, etc.?

For example, for a search result page with certain conditions (eg. logged-in), the function produces this:

<body class="search search-results logged-in admin-bar single-author two-column right-sidebar">

I need the full list for reference in creating a theme.

Cheers!

2 Answers 2

2

Several classes have been added since WordPress 2.8 (when the WPEngineer post was written). I would refer directly to the body_class() Codex entry, which currently lists the following:

  • rtl
  • home
  • blog
  • archive
  • date
  • search
  • paged
  • attachment
  • error404
  • single postid-(id)
  • page-id-(page_id)
  • attachmentid-(id)
  • attachment-(mime-type)
  • author
  • author-(user_nicename)
  • category
  • category-(slug)
  • tag
  • tag-(slug)
  • page-parent
  • page-child parent-pageid-(id)
  • page-template page-template-(template file name)
  • search-results
  • search-no-results
  • logged-in
  • paged-(page number)
  • single-paged-(page number)
  • page-paged-(page number)
  • category-paged-(page number)
  • tag-paged-(page number)
  • date-paged-(page number)
  • author-paged-(page number)
  • search-paged-(page number)
  • tax-(taxonomy name) (since 3.1)
  • term-(term name) (since 3.1)
  • admin-bar (since 3.1)
4
  • (Also @Hiranthi) Cheers! But do you know if body_class() also generates specific classes for custom post-types as well?
    – Giraldi
    Commented Jul 19, 2011 at 0:43
  • 1
    It appears that it does not; however, if you're using a custom single-{posttype}.php template file, then you get a single-{posttype} class. Commented Jul 19, 2011 at 2:57
  • Plugins can of course hook into body_class and add an unlimited number of extra classes, so this list can only contain the classes added by WP core code.
    – Jan Fabry
    Commented Jul 19, 2011 at 13:33
  • 2
    The Codex entry (and thus this list) should be updated, I see that post formats and post type archives also generate body classes. Someone should check the source and add the missing classes.
    – Jan Fabry
    Commented Jul 19, 2011 at 13:36
1

There's a list of that on WPEngineer.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.