Add a class to the body

I’m trying to add a class to the <body>.

What am I doing wrong here (in my theme’s functions.php which is loading correctly):
add_filter('body_tag_attributes', 'add_bclass'); function add_bclass( $attributes ) { $attributes['class'] = trim('My_custom_bodyclass '.$attributes['class']); return $attributes; }

It looks like there’s something odd – I could reproduce this behavior, but couldn’t find exactly what the root cause is.

However, I could work around it by adding a priority to the filter:


add_filter('body_tag_attributes', 'add_bclass', 1000);

seemed to work.

1 Like