- This topic has 7 replies, 4 voices, and was last updated 1 year, 6 months ago by Fernando.
-
AuthorPosts
-
September 4, 2020 at 1:52 am #1430378anabella
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?
September 4, 2020 at 3:39 am #1430489DavidStaffCustomer SupportHi 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.
September 4, 2020 at 4:19 am #1430527anabellaThank 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!
September 4, 2020 at 4:53 am #1430565DavidStaffCustomer SupportIn 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?September 4, 2020 at 5:37 am #1430602anabellaThanks 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.
September 4, 2020 at 6:53 am #1430668DavidStaffCustomer SupportGlad to be of help 🙂
September 27, 2022 at 3:49 am #2355068ChristianoHi 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.
Do I have to use your code? If so, where do I have to put it?
Thanks in advance! 🤗
ChristianoSeptember 27, 2022 at 6:07 pm #2355828Fernando Customer SupportHi 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?
-
AuthorPosts
- You must be logged in to reply to this topic.