Created
July 26, 2012 11:56
-
-
Save roborourke/3181655 to your computer and use it in GitHub Desktop.
Set excerpt length on the fly in wordpress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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