Skip to content

Instantly share code, notes, and snippets.

@thachpham92
Created May 27, 2013 11:00
Show Gist options
  • Save thachpham92/5656492 to your computer and use it in GitHub Desktop.
Save thachpham92/5656492 to your computer and use it in GitHub Desktop.
Limit the_excerpt
function the_excerpt_max_charlength($charlength) {
$excerpt = get_the_excerpt();
$charlength++;
if ( mb_strlen( $excerpt ) > $charlength ) {
$subex = mb_substr( $excerpt, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
echo mb_substr( $subex, 0, $excut );
} else {
echo $subex;
}
echo '[...]';
} else {
echo $excerpt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment