[Resolved] Limit for post excerpt lenght

Home Forums Support [Resolved] Limit for post excerpt lenght

Home Forums Support Limit for post excerpt lenght

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #1430378


    I´m building the posts archive using Elementor (posts widget), and I want to limit the excerpt length.
    The widget has a “excerpt length” option, but it doesn´t work on manually created excerpts (my blog posts have those)

    This is what Elementor explains: “When Elementor displays a post, if it has no excerpt, Elementor automatically generates an excerpt from the post’s content. The Excerpt Length option allows you to control the length of this auto-generated excerpt. However, the excerpt length only applies to posts in which no manual excerpt has been entered. The length specified in the Elementor widget is ignored if a manually-generated excerpt exists for a post. ”

    So, basically, now my blog page displays everything that is inside the excerpt, not matter how long that is.

    I went to Generatepress > Customizer > Layout > Blog > excerpt word count > but this is not being applied either.

    Any ideas? Any code I could add?

    Customer Support

    Hi there,

    WordPress can only trim automatic excerpts. So Excerpt length settings whether it be in the Theme or in another plugin will not change them.

    You can try adding this PHP Snippet:

    add_filter( 'get_the_excerpt', function( $excerpt, $post ) {
        if ( has_excerpt( $post ) ) {
            $excerpt_length = apply_filters( 'excerpt_length', 55 );
            $excerpt_more   = apply_filters( 'excerpt_more', ' ' . '[…]' );
            $excerpt        = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more );
        return $excerpt;
    }, 10, 2 );

    I tested it on the GP blog – and it does work with Manual excerpt ie. The themes excerpt count will apply. Not sure if it will work with Elementor though.


    Thank you su much David!

    I added your code, and now I can control the excerpt length through the Elementor Widget. Interesting!

    The only thing I´m missing is the dots […] where the text is cut.
    Any way of adding this as part of the code you sent me ?

    Thanks a lot!

    Customer Support

    In the original code you will see […] which is the Horizontal Ellipsis – it displays correct on the GP Blog – i can only assume Elementor is removing that. What if you don’t set Elementor to trim the words and try the GP excerpt length?


    Thanks David. If I don´t set Elementor to trim the words (meaning, if I leave the Excerpt Length
    field blank in Elementor) , the excerpt doesn´t show at all.
    However, I added this code and it looks good enough:

    .elementor-post__excerpt p:after {
    content: ‘ …’;

    Thank you so much for your help David. Your replies are always extremely helpful.

    Customer Support

    Glad to be of help 🙂

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