Sometimes you may have the need to output specific classes depending on the page you are viewing on a website. These additional selectors make life easier when dealing with complex CSS and JavaScript.
How to use the WordPress Body Class Function
Simply open up your specific theme’s header.php for other file that contains yourtag and insert the body_class() like so:
>
As stated by WordPress:
The echoed class attribute may include one or more of the following values for the class attribute, dependent upon the pageview.
- rtl
- home
- blog
- archive
- date
- search
- paged
- attachment
- error404
- single postid-(id)
- single-(post_type)
- 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)
- custom-background (since 3.3)