How to override excerpt length in child theme of Twenty Eleven?

my objective is to define a custom excerpt length. I know that I can do it defining a new function in my functions.php located in the child theme of the Twenty Eleven.

It should override these lines :

/**
 * Sets the post excerpt length to 40 words.
 *
 * To override this length in a child theme, remove the filter and add your own
 * function tied to the excerpt_length filter hook.
 */
function twentyeleven_excerpt_length( $length ) {
    return 40;
}
add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );

By :

function new_excerpt_length($length) {
    return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

But it does nothing. Even if I change the default value 40 by another.

Any idea?

4 Answers
4

Well I finally solved the problem. The excerpt_length function is NOT use with the excerpt box of the WordPress editor. You have to put all your content in the main area.

Leave a Comment