As it says in the title, I'm looking for multiple excerpt lengths in WordPress.
I understand you can do this in functions.php:
function twentyten_excerpt_length( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
What I want to know is how you can have multiple of these each returning different numerical values so I can get short excerpts for sidebar loops, longer excerpts for featured loops, and the longest excerpt for the main article.
Something like using these in the templates:
<?php the_excerpt('length-short') ?>
<?php the_excerpt('length-medium') ?>
<?php the_excerpt('length-long') ?>
Cheers, Dave
I think we can now use
wp_trim_words
see here. Not sure what extra data escaping and sanitization needed to use this function, but it looks interesting.Here an easy way to limit the content or the excerpt
change get_the_excerpt() by get_the_content() if you want the contents.
Regards
This is what I came up with.
Add this to your
functions.php
It can be used like this.
This is the easiest way that I know of to add filters, that are callable from one function.
I thing it is possible to create a short code , i did not try it but i wrote for you the main idea about its structure
so you can use it like so
I was looking for this feature as well and most of the functions here are good and flexible. For my own case I was looking for a solution that shows a different excerpt length only on specific pages. I'm using this:
Paste this code inside the themes functions.php file.
Here is an article about using custom excerpt length in WordPres. There is a number of Ways To Limit & Control Post Excerpt Length.
http://smallenvelop.com/limit-post-excerpt-length-in-wordpress/ I hope this will help you a lot.