Skip to content

Instantly share code, notes, and snippets.

@roborourke
Created July 26, 2012 11:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roborourke/3181655 to your computer and use it in GitHub Desktop.
Save roborourke/3181655 to your computer and use it in GitHub Desktop.
Set excerpt length on the fly in wordpress.
<?php
/**
* Sets the excerpt length for the output of the next excerpt
*
* @param int $length the number of words to show
*
* @return void
*/
function set_excerpt_length( $length = 50 ) {
add_filter( 'excerpt_length', create_function( '$l', 'return ' . intval( $length ) . ';' ), 13 );
add_filter( 'the_excerpt', create_function( '$e', 'remove_all_filters( "excerpt_length", 13 ); return $e;' ), 13 );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment