Custom excerpt legnths for specific pages

Hello I need help customizing the excerpt length for specific pages.

For the homepage excerpts I want 400 characters and for all other pages I want 800 characters.

I came up with the following code placed in functions.php

function wpdocs_custom_excerpt_length( $length ) {
    if( is_front_page() ){
        return 400;
    } else {
        return 800;
    }
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );

Unfortunately this doesnt seem to work

Anyone got a solution for this?

Thanks!

1 Answer
1

The excerpt length is the number of words, not the characters. Assuming that every word is 8 characters long in average, you might want to use this:

function wpdocs_custom_excerpt_length( $length ) {
    if( is_front_page() ){
        return 50;
    } else {
        return 100;
    }
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );

Source : WordPress codex

Leave a Comment