posts page – different lengths of excerpt

First, you need to filter excerpt_length.

Assuming you want your default excerpt length to be 50 words:

<?php
function wpse53485_filter_excerpt_length( $length ) {
    return 50;
}
add_filter( 'excerpt_length', 'wpse53485_filter_excerpt_length' );
?>

That will make all excerpts 50 words. Make sure that works first.

Then, add in an appropriate conditional, to use a different excerpt length for a static page for posts. Assuming you use a custom page template, named template-posts.php, you could filter specifically for that page template, using is_page_template().

Assuming you want the page for posts to use an excerpt length of 100 words:

<?php
function wpse53485_filter_excerpt_length( $length ) {
    if ( is_page_template( 'template-posts.php' ) ) {
        return 100;
    } else {
        return 50;
    }
}
add_filter( 'excerpt_length', 'wpse53485_filter_excerpt_length' );
?>

Using this approach, you can conditionally return any number of excerpt lengths based on various contexts.

Leave a Comment