WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to "set" the excerpt length for posts, but if I need to actually grab this integer value for something else, do you have any idea how I can grab/echo out just the value? Thanks!

share|improve this question

You could store the length like this.

function store_excerpt_length($length) {
    update_option( 'excerpt_length', $length );
    return $length;
add_filter( 'excerpt_length', 'store_excerpt_length', 1000 );

Then use the following code to get the length.

echo get_option( 'excerpt_length' );
share|improve this answer
Nice thinking, that's probably about the only way to do it. I would just add to give your filter an arbitrarily high priority (ie add_filter( 'excerpt_length', 'store_excerpt_length', 1000 ); to make sure it checks after any other filters have operated. – goldenapples Nov 29 '11 at 18:17
You have a point there @goldeapples. Will update my answer with the priority. – Joshua Abenazer Nov 29 '11 at 18:21
Awesome - thank you very much! – Zach Nov 29 '11 at 19:03
Meh - isn't actually echoing anything out. I do have a function that is setting the excerpt: function of_excerpt_length($length) { return 40; } but I wouldn't think that would actually be effecting that. Thanks! – Zach Dec 1 '11 at 20:54
You sure? Its working fine on my end. Where have you placed the code and what priority have you assigned to your filter? – Joshua Abenazer Dec 2 '11 at 3:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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