Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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
1  
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

 
discard

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.