render_block_core_post_comments_count()
Renders the core/post-comments-count block on the server.
No Hooks.
Returns
String. Returns the filtered post comments count for the current post.
Usage
render_block_core_post_comments_count( $attributes, $content, $block );
- $attributes(array) (required)
- Block attributes.
- $content(string) (required)
- Block default content.
- $block(WP_Block) (required)
- Block instance.
Changelog
| Since 6.9.0 | Introduced. |
render_block_core_post_comments_count() render block core post comments count code WP 7.0
function render_block_core_post_comments_count( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$classes = '';
if ( isset( $attributes['textAlign'] ) ) {
$classes .= 'has-text-align-' . $attributes['textAlign'];
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
get_comments_number( $block->context['postId'] )
);
}