I'm trying to limit WordPress post excerpt and I've tried some ways to do it but all of them was not the stuff that I need, to say concisely I want to limit post excerpt with a number that I use everywhere with differences.
For example, I need to make something I use it like this:
<?php the_excerpt('30') ?>
with this part of the code, I wanna limit my excerpt to 30 chars and in another place, I wanna use a different value like:
<?php the_excerpt('150') ?>
Is it in WordPress?
I'm trying to limit WordPress post excerpt and I've tried some ways to do it but all of them was not the stuff that I need, to say concisely I want to limit post excerpt with a number that I use everywhere with differences.
For example, I need to make something I use it like this:
<?php the_excerpt('30') ?>
with this part of the code, I wanna limit my excerpt to 30 chars and in another place, I wanna use a different value like:
<?php the_excerpt('150') ?>
Is it in WordPress?
1 Answer
Reset to default 0according to the documentation, it is more correct to change the length of the excerpt using add_filter:
add_filter( 'excerpt_length', function(){
return 10;
});
you can make your own function based on this, like this:
add_filter( 'excerpt_length', 'new_excerpt', 10, 1);
function new_excerpt( $lenth ){
return $length;
});
...
apply_filters( 'excerpt_length', 150 );