0

I'm trying to shorten the excerpt but it does not work. It shows the full excerpt which I write in the post edit!

I've added this to the functions.php

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

To show the excerpt I'm using in content.php:

if(has_excerpt()) { the_excerpt(); } else { the_content(); }

The above code display full excerpt, not shortened!

Without has_excerpt() if statement it displays correctly.

Where can be the problem? Any ideas what can cause this?

1
  • 1
    where is your ) for if statement?
    – ucon89
    Jan 22 '14 at 0:35
0

excerpt_length is only applied to generated excerpts-- excerpts automatically generated from the post body.

To trim your manually created excerpt, use the same function that trims the generated one-- wp_trim_words.

if(has_excerpt()) { 
  $length = apply_filters('excerpt_length',20);
  echo wp_trim_words(get_the_excerpt(),$length); 
} else { 
  the_content(); 
}

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.