What I'm trying to do:
I want to display the_excerpt
, but I have a maximum of x
characters the_excerpt
may use, but I don't want to display a couple of characters of a word, only whole words.
Some more information:
This code is on a non-single/non-permalink web page such as archives, categories, front page, and searches, that makes me unable to use <!--more-->
.
The code:
This is the code I use:
add_filter( 'excerpt_length', function( ) {
return 20;
} );
if ( have_posts() ):
while( have_posts() ): the_post();
the_excerpt( );
endwhile;
endif;