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 a WordPress Expert

Get hourly and project based theme customization, theme tweaks, and development help from world-class WordPress developers at Codeable. If you’re in Kelowna and need a custom website for your business visit our Kelowna Web Design page now to get started.