Archived topic
How to Make GenerateBlock Show Only Unique Excerpts
3 replies · Started by Andrey on January 22, 2023
Hello!
I am using DynamicContent to include post excerpt above my post meta. But I want this text to only show if a custom excerpt exists for the post. GenerateBlock seems to generate excerpt from the first words of the post.
Is there a workaround?
Thank you!
Andrey
Hi Andrey,
Try adding check-custom-excerpt to the class list of the Headline Block.
Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
Then, add this snippet:
add_filter( 'render_block', function( $block_content, $block ) {
if ( !has_excerpt() && !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'check-custom-excerpt' ) !== false ) {
return '';
}
return $block_content;
}, 10, 2 );
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Thank you so much, Fernando!
This solution worked like a charm!
You're welcome, Andrey!