Site logo

Archived topic

Excerpt not displaying exact number of words in one post

5 replies · Started by Patricia on February 16, 2021

Viewing posts 1–6 of 6

Hi there,

try adding this CSS:

.generate-columns .inside-article,
.generate-columns .inside-article .entry-summary,
.generate-columns .inside-article .entry-summary p {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-between;
}

Hi David,

thanks for your reply.

nope didnt work. it affects the last post.

what I was concerned about was this post 'How To Cook A Ribeye Steak In A Frying Pan' https://prnt.sc/zwvsvf as it has more words than the others.. the except should not go beyond 20 words as I have set it here https://prnt.sc/zto2ik.

Hi there,

We can try forcing a trim on the excerpt.

Try this PHP 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, 20, '...' ),
            get_permalink(),
            __( 'Read more', 'generatepress' )
        );
    }
    return $output;
}

Here's how to add PHP
https://docs.generatepress.com/article/adding-php/

Hi Elvin,

yup i tried this code before but didnt work.

anyways, i had it fixed now. thankyou for your help :)

Nice one. Thank you for letting us know. Glad you got it sorted. :D

This archived topic is closed to new replies.