WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(); ?>">
share|improve this question
up vote 1 down vote accepted

directly in the body tag line:

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


share|improve this answer

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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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