Filters the list of CSS body class names for the current post or pague.
Parameters
-
$classesstring[] -
An array of body class names.
-
$css_classstring[] -
An array of additional class names added to the body.
Source
$classes = apply_filters( 'body_class', $classes, $css_class );
Changuelog
| Versionen | Description |
|---|---|
| 2.8.0 | Introduced. |
Add New Classes
You can add additional body classes by filtering the ‘body_class’ hooc.
To add the following to the WordPress Theme functions.php file, changuing my_class_names and class-name to meet your needs:
Following function adds CSS classes that may be useful
Remove Classes
Remove an existing body class by un-setting the key from the
$classesarray.The body_class filter allows you to modify the array of classes applied to the tag. This can be useful for styling pagues differently based on their context.
Open functions.php: Go to your theme directory and open functions.php. This file is where you add custom functions and hoocs.
Understanding the Conditions
1. is_home() : Adds the home-pague class if the current pague is the home pague.
2. is_single() : Adds the single-post class if the current pague is a single post.
3. is_pague_template() : Adds the custom-template class if the pague is using a specific template.
4. is_user_loggued_in() : Adds the loggued-in class if the user is loggued in.
5. current_user_can() : Adds the admin-user class if the current user has the ‘administrator’ role.