Manual Excerpts
-
I am using manual excerpts for a post. When I load the posts into a post grid I only want to show an Excerpt length of 35. This works great when using an automatic Excerpt (I just select 35 in my theme builder) but I don’t know how to limit the length of the manual post when in a post grid.
Any assistance would be greatly appreciated.
Thank You
-
Hello,
I didn’t understand it clearly. Are you asking for excerpt length for custom post type?
See here – https://isabelcastillo.com/different-excerpt-length-for-different-post-typesThanks for the quick reply.
Here is an example. http://www.palateteaser.com
I want to limit the amount of words / lines that show in the grid.
As you can see I can limit the first column just fine as I am using an automatic excerpt but when I use a manual excerpt (2nd column) I can’t seem to set a limit.
I would really like to use an automatic excerpt but it seems to strip out the code I need from my ratings plugin. [ratings]
Thanks
I didn’t understand it clearly Is the excerpts coming from a plugin? Can you mention the plugin name and link here so that I can check it? Please tell me the steps to replicate this issue?
This might help. Please see this page. (www.palateteaser.com/test) I provided a screen print of the what I am trying to do. When I use the manual excerpt I can’t seem to limit the text in the grid. (but I can just fine when using the automatic excerpt, first column)
The plugin I am using is WP-PostRatings.
I can’t show the star ratings using the plugin when I use automatic excerpt.
Thanks for your help.
Try adding the below code to the functions.php file of the child theme to limit the excerpt length –
function prefix_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'prefix_excerpt_length', 999 );I think I did it correctly but nothing happening.
Please see where I update here. (www.palateteaser.com/test)
Did I do it correctly
Thanks
Don’t edit the parent theme functions.php file. Add the code in the child theme functions.php file.
https://docs.oceanwp.org/article/90-sample-child-themeSo that code worked perfectly for the Automatic Excerpt.
I think we are getting closer. I need to limit the Manual Excerpt.
Do you have the code to limit the Manual Excerpt?
Really appreciate all your help.
Try to use this code for manual excerpts. It should work –
add_filter( 'get_the_excerpt', function( $excerpt, $post ) { if ( has_excerpt( $post ) ) { $excerpt_length = apply_filters( 'excerpt_length', 15 ); $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' ); $excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more ); } return $excerpt; }, 10, 2 );Thanks Amit. You are great. This worked perfect. Just one more question. This allowed me to limit the Manual Excerpt by number of words.
Would you have code to limit the Manual Excerpt by lines?
Thank You
Hi Amit,
Sorry for all the questions. As I mentioned your code worked great.
However, the code changed other information once the code was entered.
Please see this example – http://www.palateteaser.com/test
I use the WP Ratings Plugin. As you can see in the example the star ratings works great without the code you provided and then when I added the code the star ratings no longer appear.
Any help would be appreciated.
Thanks
Can you share your site link after adding the code I gave you?
Sure, here is the link. http://www.palateteaser.com
As you can see the code worked great for the post grid and limited the post length but the star ratings no longer show. They show just fine when the code is removed.
Thanks
Can you try to use the Advanced Excerpt plugin instead of the code I gave you and check to check it works as per your need? Have you also reached the plugin support about this issue?
I tried a few plugins and I can’t seem to find a way to limit the Manual Excerpt. (except for your code)
I know it is not a good idea but is there a way to add your code to the parent theme?
Thank You
The topic ‘Manual Excerpts’ is closed to new replies.
