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?
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(); ?>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With