[Resolved] Limit for post excerpt lenght

Home Forums Support [Resolved] Limit for post excerpt lenght

Home Forums Support Limit for post excerpt lenght

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1430378
    anabella

    Hi,

    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?

    #1430489
    David
    Staff
    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.

    #1430527
    anabella

    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!

    #1430565
    David
    Staff
    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?

    #1430602
    anabella

    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.

    #1430668
    David
    Staff
    Customer Support

    Glad to be of help 🙂

    #2355068
    Christiano

    Hi David, I just switched to GeneratePress and I’m staging my site in order to gain speed. I choosed the Scribe layout.

    I have the same problem… I would like to trim the excerpt in order to correctly align the “read the article” buttons.

    Buttons not aligned…

    Do I have to use your code? If so, where do I have to put it?

    Thanks in advance! 🤗
    Christiano

    #2355828
    Fernando
    Customer Support

    Hi Christiano,

    We can try to align the buttons without the need to trim.

    Can you start a new topic and share the link to the page in question?

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