Site logo

[Support request] Query loop – “ custom excerpts length change won’t show.

Home Forums Support [Support request] Query loop – “ custom excerpts length change won’t show.

Home Forums Support Query loop – “ custom excerpts length change won’t show.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2505216
    Matthias

    In the backend – you can adjust the Excerpt length and it shows in query loop.
    But in front end it shows the whole excerpt text.

    It works when custom excerpt field is empty – as expected 🙂

    I’m tranfering a site to GP premium and GB pro.
    I need to transfer hundreds of old posts and all have “custom excerpts”

    Is there a way around to adjust the excerpt length?

    Plugins:
    GB 1.60
    GB pro 1.4.0
    GP 3.2.4
    GP premium 2.22

    #2505350
    Fernando
    Customer Support

    Hi Matthias,

    There’s a possible way around it. Try adding this Snippet:

    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
        $output = $excerpt;
    
        if ( has_excerpt() ) {
            $output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>',
                wp_trim_words( $excerpt, 2, '...' ),
                get_permalink(),
                __( 'Read more', 'generatepress' )
            );
        }
    	
        return $output;
    }

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    Change 2 in wp_trim_words( $excerpt, 2, '...' ) to the preferred excerpt length.

    #2505357
    Matthias

    Fernando,
    Thank you so much this is Great! (Team Generatepress ROCKS)
    I spent hours but couldn’t find a solution.

    Only one thing I don’t need the button “read more”.

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