Add Custom Body Class To WordPress Template

This snippet can be added to the top of your page or post template php file to add a custom body class.

When creating a custom template for a page, it is useful to be able to give that template a custom body class.

This snippet can be added to the top of your page or post template php file to do that.

// Add custom body class to the head
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
   $classes[] = 'name-of-css-class-goes-here';
   return $classes;
}

Hire WordPress Experts at Codeable.

The only WordPress exclusive freelancer platform that connects thousands of customers with the top WordPress freelance experts to work on projects of any size. 

Free estimate • No obligation to hire • 100% risk-free