Site logo

Archived topic

Query loop - “ custom excerpts length change won’t show.

3 replies · Started by Matthias on January 22, 2023

Viewing posts 1–4 of 4

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

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.

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".

This archived topic is closed to new replies.