Dynamic the_excerpt() length in WordPress

wordpress-featured

Add in function.php in your theme

	function the_excerpt_dynamic($length) { // Outputs an excerpt of variable length (in characters)
		global $post;
		$text = $post->post_exerpt;
		if ( '' == $text ) {
			$text = get_the_content('');
			$text = apply_filters('the_content', $text);
			$text = str_replace(']]>', ']]>', $text);
		}
			$text = strip_shortcodes( $text ); // optional, recommended
			$text = strip_tags($text);  // use ' $text = strip_tags($text,'
 
<a>'); ' to keep some formats; optional $output = strlen($text); if($output</a>

Call in loop:

the_excerpt_dynamic(250)


Leave a Comment

You must be logged in to post a comment.