Created
May 26, 2013 13:03
-
-
Save jswhisperer/5652720 to your computer and use it in GitHub Desktop.
WordPress: Limit words function
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
<?php | |
function limit_words($string, $word_limit) { | |
$words = explode(' ', $string); | |
return implode(' ', array_slice($words, 0, $word_limit)); | |
} | |
?> | |
#usage: | |
<?php echo limit_words(get_the_excerpt(), '41'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment