Created
July 14, 2016 04:08
-
-
Save rafinkarki/74a52ffc53c2d13937b7658a2e44eb97 to your computer and use it in GitHub Desktop.
excerpt max length
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
//excerpt max charlenght | |
function the_excerpt_max_charlength($charlength) { | |
$excerpt = get_the_excerpt(); | |
$charlength++; | |
if ( mb_strlen( $excerpt ) > $charlength ) { | |
$subex = mb_substr( $excerpt, 0, $charlength - 7 ); | |
$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; | |
} | |
} | |
//And use this | |
<?php the_excerpt_max_charlength(100);?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment