Body_class wordpress doest work

I was trying to put a class inside html body tag with php for my wordpress theme. I am looking at wordpress code and I have to use the following and add it to my functions.php file:

add_filter( 'body_class', 'my_class_names' );
function my_class_names( $classes ) {
    // add 'class-name' to the $classes array
    $classes[] = 'class-name';
    // return the $classes array
    return $classes;
}

      

Only it doesn't work for me. Does anyone know what this might be?

Casper

+3


source to share


1 answer


This code looks correct.

So, you have to make sure that you are calling body_class () correctly on the tag in the opening tag. It is usually found in header.php and should look like this:



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

      

+6


source







All Articles