So I'm trying to change the standard post excerpt length.

Every single blog post on the web tells me to do it with a filter like this:

add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function custom_excerpt_length( $length ) {
return 15; // Length of the excerpt in number of words

Problem is there is no change to the excerpt length. All the text is being output and not just 15 words. I have no idea why this doesn't work when it's supposed to be the solution.

I'm using <?php the_excerpt(); ?> in the post loop on home.php, category.php and tag.php to output the excerpt.

  • 1
    excerpt_length only applies to the automatically generated excerpt. If you have one entered into the Excerpt box it won't be affected. You're saying that all the text is appearing though? Are you certain you're using the_excerpt() and not the_content()? Apr 4 '18 at 12:51
  • Aha. That explains it. With "All the text" I mean all the text that I have entered in the excerpt textarea for a custom excerpt. How would I limit the amount of words for the entered custom excerpt then?
    – Skovsgaard
    Apr 4 '18 at 12:55

For anyone wondering, as custom excerpts don't get trimmed by the excerpt_length filter hook, try adding this filter:

function trim_custom_excerpt($excerpt) {
    if (has_excerpt()) {
        $excerpt = wp_trim_words(get_the_excerpt(), apply_filters("excerpt_length", 55));

    return $excerpt;

add_filter("the_excerpt", "trim_custom_excerpt", 999);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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