Skip to content

Commit

Permalink
Post excerpt: Don't print the wrapper when there is no excerpt (#35749)
Browse files Browse the repository at this point in the history
* Post excerpt: Don't print the wrapper when there is no excerpt
  • Loading branch information
carolinan authored Oct 21, 2021
1 parent e1db831 commit bd1a5b7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/block-library/src/post-excerpt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
return '';
}

$excerpt = get_the_excerpt( $block->context['postId'] );

if ( empty( $excerpt ) ) {
return '';
}

$more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . $attributes['moreText'] . '</a>' : '';
$filter_excerpt_more = function( $more ) use ( $more_text ) {
return empty( $more_text ) ? $more : '';
Expand All @@ -38,7 +44,7 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );

$content = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] );
$content = '<p class="wp-block-post-excerpt__excerpt">' . $excerpt;
$show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];
if ( $show_more_on_new_line && ! empty( $more_text ) ) {
$content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';
Expand Down

0 comments on commit bd1a5b7

Please sign in to comment.