diff --git a/packages/block-library/src/comment-template/index.php b/packages/block-library/src/comment-template/index.php index 49ca8561e2d47a..770959854b58ad 100644 --- a/packages/block-library/src/comment-template/index.php +++ b/packages/block-library/src/comment-template/index.php @@ -16,6 +16,8 @@ */ function block_core_comment_template_render_comments( $comments, $block ) { global $comment_depth; + $thread_comments = get_option( 'thread_comments' ); + $thread_comments_depth = get_option( 'thread_comments_depth' ); if ( empty( $comment_depth ) ) { $comment_depth = 1; @@ -46,14 +48,22 @@ function block_core_comment_template_render_comments( $comments, $block ) { // If the comment has children, recurse to create the HTML for the nested // comments. - if ( ! empty( $children ) ) { - $comment_depth += 1; - $inner_content = block_core_comment_template_render_comments( - $children, - $block - ); - $block_content .= sprintf( '
    %1$s
', $inner_content ); - $comment_depth -= 1; + if ( ! empty( $children ) && ! empty( $thread_comments ) ) { + if ( $comment_depth < $thread_comments_depth ) { + $comment_depth += 1; + $inner_content = block_core_comment_template_render_comments( + $children, + $block + ); + $block_content .= sprintf( '
    %1$s
', $inner_content ); + $comment_depth -= 1; + } else { + $inner_content = block_core_comment_template_render_comments( + $children, + $block + ); + $block_content .= sprintf( $inner_content ); + } } $content .= sprintf( '
  • %3$s
  • ', $comment->comment_ID, $comment_classes, $block_content );