Archived topic
Add body class when post comments are active
3 replies · Started by George on November 8, 2020
Viewing posts 1–4 of 4
I want to modify the layout depended on whether the bottom comment box in a post is active or not. Is there a way to add a body class when the comment form is active?
Hi there,
you can try checking if comments are open and appending a new body class:
add_filter( 'body_class', function( $classes ) {
if ( !comments_open() ) {
return $classes;
}
return array_merge( $classes, array( 'class-name' ) );
} );
This is amazing, David, thank you!
Glad to be of help
This archived topic is closed to new replies.