My theme already has a specific body class filter for the colorscheme it uses. How can I also add a body class filter for the page name? Basically I want to combine these statements:

<body <?php body_class(); ?>>
<body class="<?php echo get_stencil(); ?>">

I've been trying but I just keep getting error messages with variations like this:

 <body class="<?php echo get_stencil(); ?> <?php body_class(); ?>">

directly in the body tag line:

<body <?php body_class( get_stencil() ); ?>>



Add following filter code in functions.php to add any custom class to body.

// Add specific CSS class by filter
function my_class_names($classes) {
// add 'class-name' to the $classes array
$classes[] = 'class-name';
// return the $classes array
return $classes;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.