I want to conditionally add a body class depending on what template is being used.

I can’t figure out why the following code is not working…

function damsonhomes_body_classes( $classes ) {

  if (is_page_template('single.php')) {

    $classes[] = 'sans-hero';


  return $classes;


add_filter( 'body_class', 'damsonhomes_body_classes');

Thanks all

Read more here: Why isn’t is_page_template() adding a body class?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: