Skip to content

Commit

Permalink
fix (posts block): "<a" appearing in posts excerpt (#3301)
Browse files Browse the repository at this point in the history
Co-authored-by: [email protected] <>
  • Loading branch information
bfintal authored Sep 5, 2024
1 parent da1bfb8 commit 0288c5d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/block/posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ public static function get_excerpt_by_post_id( $post_id, $post = null, $max_exce
$exploded_excerpt = explode( ' ', $excerpt );
$trim_to_length = (int) $max_excerpt;
if ( count( $exploded_excerpt ) > $trim_to_length ) {
$excerpt = implode( ' ', array_slice( $exploded_excerpt, 0, $trim_to_length ) ) . '...';
$excerpt = wp_trim_words( $excerpt, $trim_to_length, '' );
// If last word does not contain '…' or '...', add it
if ( substr( $excerpt, -1 ) !== '' && substr( $excerpt, -3 ) !== '...' && substr( $excerpt, -3 ) !== '' ) {
$excerpt .= '...';
}
}
}

Expand Down

0 comments on commit 0288c5d

Please sign in to comment.