Last active
May 21, 2016 02:18
-
-
Save kjbrum/5d90663036d64e5f5c9f to your computer and use it in GitHub Desktop.
Create a custom length excerpt.
This file contains hidden or 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 | |
/** | |
* Create a custom length excerpt. | |
* | |
* @param integer $limit How many words you want returned | |
* @return string $content The content string | |
*/ | |
function wp_excerpt_length( $limit=50 ) { | |
$content = get_the_content(); | |
$content = preg_replace( '/\[.+\]/', '', $content ); | |
$content = apply_filters( 'the_content', $content ); | |
$content = str_replace( ']]>', ']]>', $content ); | |
$content = strip_tags( $content ); | |
$content = explode( ' ', $content, $limit ); | |
if( count( $content) >= $limit ) { | |
array_pop( $content ); | |
$content = implode( ' ', $content ) . '...'; | |
} else { | |
$content = implode( ' ', $content ); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment