I have a search results page and would like to show longer results then the standard excerpt length in WP (which is 55 words).
Here's my code so far, which I added to functions.php
<?php if (is_search()) {
function custom_excerpt_length( $length ) {
return 400;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
} ?>
I expected that the conditional statement would cause the excepts to show longer now. But this does not happen.
CodePudding user response:
Put the if statement in the function
function custom_excerpt_length( $length ) {
if (is_search()) {
return 400;
}
else{
return $length;
}
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );