apply_filters( 'body_class', string[] $classes , string[] $class )
Filters the list of CSS body class names for the current post or page.
Description Description
Parameters Parameters
- $classes
-
(string[]) An array of body class names.
- $class
-
(string[]) An array of additional class names added to the body.
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Remove Classes
Remove an existing body class by un-setting the key from the
$classesarray.// Removes a class from the body_class array. add_filter( 'body_class', function( $classes ) { if ( isset( $classes['class-to-remove'] ) ) { unset( $classes['class-to-remove'] ); } return $classes; } );Add New Classes
You can add additional body classes by filtering the {@see ‘body_class’} hook.
To add the following to the WordPress Theme functions.php file, changing my_class_names and class-name to meet your needs:
// Add specific CSS class by filter. add_filter( 'body_class', function( $classes ) { return array_merge( $classes, array( 'class-name' ) ); } );