Browse Source

show audio block on the excerpt

Maggie Cabrera 4 years ago
parent
commit
4907eafa53
1 changed files with 15 additions and 2 deletions
  1. 15 2
      spearhead/functions.php

+ 15 - 2
spearhead/functions.php

@@ -227,13 +227,26 @@ function spearhead_excerpt_more() {
 }
 
 function spearhead_the_excerpt( $excerpt ) {
+
+	$audio_block = '';
+	if ( has_block( 'audio' ) ) {
+		$post   = get_post();
+		$blocks = parse_blocks( $post->post_content );
+		foreach ( $blocks as $block ) {
+			if ( 'core/audio' === $block['blockName'] ) {
+				$audio_block .= '<div class="excerpt-audio-block">' . $block['innerHTML'] . '</div>';
+				break;
+			}
+		}
+	}
+
 	// For cases where the post excerpt is empty
 	// (but the post might have content)
 	if ( 0 === strlen( $excerpt ) ) {
-		return $excerpt;
+		return $excerpt . $audio_block;
 	}
 
-	return $excerpt . '<span class="excerpt-more-link">' . spearhead_more_link() . '</span>';
+	return $excerpt . '<span class="excerpt-more-link">' . spearhead_more_link() . '</span>' . $audio_block;
 }
 
 /**