Created
November 18, 2013 20:33
-
-
Save FriendlyWP/7534825 to your computer and use it in GitHub Desktop.
Limit words in excerpts
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
/*** | |
**** LIMIT WORDS IN EXCERPTS (or any supplied content) | |
Usage: | |
$text = get_the_excerpt(); | |
echo string_limit_words($text, 40); | |
*/ | |
function string_limit_words($string, $word_limit) { | |
$words = explode(' ', $string, ($word_limit + 1)); | |
if(count($words) > $word_limit) | |
array_pop($words); | |
return implode(' ', $words); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment