[Resolved] Add body class when post comments are active

Home Forums Support [Resolved] Add body class when post comments are active

Home Forums Support Add body class when post comments are active

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1522623
    George

    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?

    #1522701
    David
    Staff
    Customer Support

    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' ) );
    } );
    #1522737
    George

    This is amazing, David, thank you!

    #1522844
    David
    Staff
    Customer Support

    Glad to be of help

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.