0

I have a problem displaying custom excerpt length. I've searched for a solution on wordpress stackexchange and found this:

    remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); 
add_filter('excerpt_length', 'new_excerpt_length');
function new_excerpt_length($length) {
  return 50;
}

When adding this to functions.php I still get the same 3 line excerpt as before. If I change the return statement to something else like, return 8 or return 17, I still get the same excerpt as before.

The excerpt function is inserted into content.php like this:

<div class="entry-content">
            <?php the_excerpt(); ?>
            <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
        </div><!-- .entry-content -->
        <?php endif; ?>

What am I doing wrong here?

1 Answer 1

0

In your second approach remove <?php the_excerpt(); ?> and replace it with:

<?php echo wp_trim_words( get_the_excerpt() , 60); ?>

it will show 60 words change to word amount you want.

Edit
I replaced exact following in content.php:

<div class="entry-content">
<?php the_content( __( '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 -->

with this:

with:

<div class="entry-content">
<?php echo wp_trim_words( get_the_excerpt() , 60); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->

Works like a charm if not than you have changed already some more somewhere else in the code?
I assume you made a child-theme of it or are you changing original code? When it is in the org theme..put your copy you made before changing anything back in and replace exact the code as shown here, you will see it works! If it is in your child theme..replace it also with a fresh copy of that file and replace exact code as shown. I can change it into any number..even with not adding excerpt in backend it shows exact that what it should.

Note: all done and checked in a "virgin" Twenty eleven theme. It works if you follow and do exact as shown and you didn't made any changes in the functions.php or somewhere else which overrules this. Good luck and have a nice weekend.

2
  • Tried that in content.php but I still get the same 3 lines excerpt which is very weird. Tried to change that 60 parameter from your code to something else like 7, 23, but nothing seems to change in the excerpt lenght.
    – user44148
    Commented Dec 20, 2013 at 19:15
  • I assume you removed at least the code from the functions.php before you also changed some in the content.php.
    – Charles
    Commented Dec 20, 2013 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.