Hello,
I created a single layout for blog posts using Pro Theme / Cornerstone. I’m using the “Comment List” and “Comment Form” elements to display the necessary information. I have now disabled comments for a specific post. The WordPress user interface (editor) explicitly states that disabling comments keeps existing comments visible; therefore, only the form should be hidden. However, what actually happens is that both the form and the existing comments are hidden.
I hope you can see the reason.
Many thanks and best regards,
Hannes
Hey Hannes,
In the theme files, specifically in comment-list.php, the layout rendering logic for the Comment List element has a conditional check that restricts output to only run when comments are open:
if ( have_comments() && comments_open() && $count > 0 ) { // 01
$list = cs_tag( $comment_list_style, $list_args, $list_template );
}
Why this happens:
- When you disable comments for a post in WordPress,
comments_open()returnsfalse. - Because
comments_open()is required as part of theifcondition for the Cornerstone Comment List element, the check evaluates tofalse. - As a result, the element does not build or render the list (
$listremainsnull), causing the existing comments to be hidden along with the comment form.
In that case, it doesn’t align with how the WordPress comment function is designed to work. As the WordPress user interface (editor) indicates, closing comments simply disables the comment form; it does not hide existing comments. That is the intended behavior, and it makes sense. The fact that the Pro theme handles this differently suggests a bug—or is this intentional?
If it isn’t a bug, is there a code snippet or filter function we can add to change this behavior?
Many thanks and best regards,
Hannes
Hey Hannes,
I believe this is not intentional but rather an oversight so I’m going to report this to our dev team. For now, try adding the following snippet in your child theme’s functions.php and tell us if it works. This will help or lead us to the solution.
add_filter( 'cs_element_render_function_comment-list', function( $render_fn, $data ) {
return function( $data ) {
extract( $data );
$atts = [
'class' => array_merge( [ 'x-comment-markup', 'x-comment-list' ], $data['classes'] )
];
if ( isset( $id ) && ! empty( $id ) ) {
$atts['id'] = $id;
}
if ( isset( $data['style'] ) && ! empty( $data['style'] ) ) {
$atts['style'] = $data['style'];
}
$atts = cs_apply_effect( $atts, $data );
$args = array(
'style' => $comment_list_style,
'avatar_size' => $comment_list_avatar_size,
'short_ping' => false,
);
if ( function_exists( 'x_get_stack' ) ) {
$stack = x_get_stack();
$callback = cs_stack_is_custom()
? 'cs_stack_comment_list'
: 'x_' . $stack . '_comment';
$args['callback'] = $callback;
}
if ( $comment_list_order === 'newest' ) {
$args['reverse_top_level'] = true;
}
$shim_template = function() { return cornerstone()->path . '/includes/views/app/shim.php'; };
add_filter( 'comments_template', $shim_template );
comments_template();
remove_filter( 'comments_template', $shim_template );
$count = intval( get_comments_number() );
$list = null;
$output_list_comments = null;
$output_no_comments = null;
$output_closed = null;
ob_start();
echo wp_list_comments( $args );
$list_template = ob_get_clean();
$list_args = [ 'class' => 'x-comments-list', 'id' => 'comments' ];
// FIX: Render the comment list if there are comments, even if comments are closed
if ( have_comments() && $count > 0 ) {
$list = cs_tag( $comment_list_style, $list_args, $list_template );
}
return cs_tag( 'div', $atts, [
$list,
$output_no_comments,
$output_closed
]);
};
}, 10, 2 );
Thanks.
Unfortunately, unchanged.
Hey @salilou,
Thank you for reporting. I’ll list this in our issue tracker to be investigated more deeply by our development team. Please stay tuned for updates.
Thank you. I stay tuned!
Thank you.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.