body_class wordpress doesn’t work

I was trying to place a class inside the body tag of the html with php for my wordpress theme.
I look at the codex of wordpress and I should 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 does this not work for me. Does anyone have any idea what this could be?

Related posts

Leave a Reply

2 comments

  1. This code appears to be correct.

    So you have to make sure that you’re calling body_class() correctly in the theme in the opening body tag.
    It is usually found in header.php and should be similar to this:

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