excerpt length in Child Theme

Once again my amature php skills have me pinned down by its strings!

I am trying to change the excerpt length of the post summaries on my WordPress blog page. So far I have created a child theme, replaces the content.php file code to

Read More
<div class="entry-content">
            <?php the_excerpt( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?>
            <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
        </div><!-- .entry-content -->

and added a functions file with the following code

    <?php

function CHILDTHEME_excerpt_length($length) {
    return 600;
}
add_filter('excerpt_length', 'CHILDTHEME_excerpt_length'); ?>

AND what do you know…… It still remains the same length of summary on the blog page as before. What am I doing wrong?

All help is very much appreciated as always

Related posts

Leave a Reply

2 comments

  1. You must set the filter priority right:

    add_filter('excerpt_length', 'CHILDTHEME_excerpt_length', 999);
    

    Without specifying the priority WordPress filter on this function will run last and override what you set here.

  2. You probably have a filter that is running after yours and resetting the length. You can set a higher priority, this can be guesswork until you get it high enough. Another option is to remove all the existing filters for this hook before you add yours:

    function my_excerpt_length($length){
       return 400;
    }
    remove_all_filters( 'excerpt_length' );
    add_filter( 'excerpt_length', 'my_excerpt_length', 999 );