0

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!

1 Answer 1

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' );
5
  • 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. Nov 29, 2011 at 18:17
  • You have a point there @goldeapples. Will update my answer with the priority. Nov 29, 2011 at 18:21
  • 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, 2011 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? Dec 2, 2011 at 3:33
  • The function that you are calling can also be modified in the following manner of_excerpt_length($length) { $length = 40; update_option( 'excerpt_length', $length ); return $length; } Dec 2, 2011 at 8:02

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.