Site logo

[Support request] How to Make GenerateBlock Show Only Unique Excerpts

Home Forums Support [Support request] How to Make GenerateBlock Show Only Unique Excerpts

Home Forums Support How to Make GenerateBlock Show Only Unique Excerpts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2505122
    Andrey

    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

    #2505313
    Fernando
    Customer Support

    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

    #2505574
    Andrey

    Thank you so much, Fernando!

    This solution worked like a charm!

    #2506548
    Fernando
    Customer Support

    You’re welcome, Andrey!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.