WordPress add Class to Body

Glenn Blog Leave a Comment

Add the following snippet to your WordPress Theme functions.php file to add a custom class to the body element:_

add_filter( 'body_class','my_body_classes' );
function my_body_classes( $classes ) {
 
    $classes[] = 'class-name';
     
    return $classes;
     
}

Change ‘class-name’ to your class or an existing class on other pages like ‘woocommerce’.

About the Author
WordPress add Class to Body WordPress add Class to Body 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced Web Designer / Web Developer (Webflow, WordPress, Weebly & Custom), Front-end / Back-end Developer & New Media Specialist, with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries, built up over a number of years.