You can hook the get_the_excerpt
filter with parse_blocks
to extract the content of your post.
add_filter( 'get_the_excerpt', 'se378694_default_excerpt', 10, 2 );
function se378694_default_excerpt( string $post_excerpt, WP_Post $post ):string {
if ( empty( $post_excerpt ) ) {
$blocks = parse_blocks( $post->post_content );
// check if the first block matches the type of content you want for your excerpt
if ( ... ) {
$post_excerpt = render_block( $blocks[ 0 ] );
}
}
}
You can use render_block() if you want to get the final content of any block in your post content.
And parse_blocks() to convert the post content (string) into an array of blocks.
Related Posts:
- Using wp_trim_excerpt to get the_excerpt() outside the loop
- How to get the unfiltered excerpt, without […] or auto-excerpting
- Remove “Continue Reading” Link From the Teaser Excerpt Only
- Modify youtube video size on one page and show another size on different page
- Issue with enabling formatting in excerpts in WordPress
- Excerpt Word Count
- Limit the_excerpt in the first point (.) of the sentence
- How to show only manual / custom excerpts?
- Excerpts that don’t truncate words
- Spacing within the excerpt
- Custom Excerpt is returning 52 characters and not 52 words
- “Read more” link doesn’t show up when the post length is under the excerpt length
- the_excerpt Read More Filter
- How to get the excerpts of all children pages
- Custom excerpt showing first paragraph (with HTML formatting)
- Empty excerpt using wp_get_recent_posts
- Different ‘read more’ links
- The excerpt: Display text OR image OR video
- How to display only the excerpt in the blog/posts page with Gutenberg?
- Read More for Excerpt not working
- First letter cutting off in excerpt
- How to correctly limit the content and strip HTML?
- Getting the_excerpt to link to child pages [closed]
- Getting first 20 words without excerpt
- Change excerpt length of first post
- Display oEmbed in the_excerpt
- Auto Populate Excerpt Field
- Remove Text within Header tags in the Excerpt
- Line in excerpt and max 5 lines
- Show the excerpt in a loop
- Include post title in readmore link?
- Excerpts automatically remove paragraph space
- Excerpt using Read More Tag
- How to show post content before read more tag (excerpt) for password protected posts?
- How to apply excerpt length only on front end?
- get_the_excerpt() issues – returns the excerpt twice or not at all?
- Bug in the_excerpt() function
- Excerpt content
- Show excerpts of posts on P2 Home page
- How to change the length of excerpt() method?
- Removing h3s in excerpt output?
- get_the_excerpt without images
- How to properly show the Excerpt only if it exists?
- The excerpt doesn’t add Read more
- How to get excerpt of the recent posts
- Limit the size of the post excerpt
- excerpt box not visible
- I can’t modify the ‘Continue reading…’ link of the_excerpt
- Show Excerpts In Twenty Eleven Theme
- How do you edit the html of teaser excerpts
- Add custom read more to the_excerpt and
- Remove [ and ] from excerpt
- the_excerpt is not limiting my post page to 55 words?
- Is it possible to use words as starting and ending points of excerpt parameters?
- I want to show post excerpt and cap it at 20 words [duplicate]
- Split the_content into two parts
- How to replace get_the_excerpt with first N words of post article while stripping html
- How to edit a typo in excerpt?
- My post excerpt does not work
- How to remove excerpt white spaces
- The excerpt suffix won’t go away
- making the […] clickable
- Adding […] string for a custom excerpt function
- Replace text in excerpt
- How to achieve two different excerpt types on one WordPress site?
- Modify excerpt link
- Reblog WordPress to another WordPress?
- Append Second Link to Read More
- Twenty Eleven: Home Page, View full post of most recent post & Summary of the rest
- How to enable excerpts just on the “Posts page”
- Display Full Content Instead of Excerpt
- How to use limit post content on archive page in WordPress?
- Excerpts not showing
- Keep excerpt from stripping URLs and enable autoembed for youtube ONLY?
- Excerpt being limited too early
- Help needed using wp_trim_words
- Excerpt of certain page to display on home page
- get_the_excerpt adding unwanted links to output html
- Excerpt functions is removing the forward slash on the url
- the_excerpt() doesn’t return the Excerpt field content
- How to add a new line to an excerpt?
- 2 posts same excerpt?
- Excerpt displays the current page excerpt not one being pulled
- Edit the excerpt before it is shown
- Is there a html tag filter for the excerpt?
- Add rel=lightbox to custom string
- multiple excerpt length and styles
- how to use the_excerpt for two post queries?
- WordPress Post Format If Statement?
- Excerpt Problems
- Function to shorten string without cutting off last word
- How to show excerpt field
- Get a raw value of excerpt
- Post content not showing
- Need to show post summary in sidebar
- Limited excerpt with readmore
- Setting post excerpt length in php wordpress code, Should will help to save DB size?
- Format main page post excerpt previews
- Is there a way to display the ‘Read more’ link if it’s within a range?
- HTML in excerpt WordPress 6.2.2