It’s Used to All class add to wordpress body element Using body_class(); function.
Specifically, it’s used to adding body classes, removing body classes, conditionally adding body classes and some use cases.
The Body Class: What Can It Be Used For?
The body class in WordPress is a class or series of classes that are applied to the HTML body element. This is useful for applying unique styles to different areas of a WordPress site as body classes can be added conditionally.
- This is a really simple way to add body classes and is especially useful if you are creating a theme, using this below code is header.php body element
< body
<?php body_class();
?> >
Adding Multiple Body Classes
There may be times when you want to add more than one body class. This can be achieved using a simple
< body <?php body_class( array( "class-one", "class-two", "class-three" ) ); ?>>
Conditionally Adding a Body Class
This example uses the WooCommerce conditional method of is_shop() :
<?php if ( is_shop() ) { body_class( 'is-woocommerce-shop' ); } else { body_class(); } ?>
Adding a Body Class by Filter
It’s possible to use a WordPress filter to add a body class, This code can either go in your themes functions.php or within your plugin.
add_filter( 'body_class','my_body_classes' );
function my_body_classes( $classes ) {
$classes[] = 'your-custom-class-name';
return $classes;
}
refer Link For More Knowledge