Last active
August 29, 2015 13:59
-
-
Save emaildano/10478156 to your computer and use it in GitHub Desktop.
Limit by word count 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 Word Count, Strip Tags from Result | |
function trunc($phrase, $max_words) { | |
$phrase_array = explode(' ',strip_tags($phrase)); | |
if(count($phrase_array) > $max_words && $max_words > 0) | |
; | |
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...'; | |
return $phrase; | |
} |
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 $excerpt = get_the_excerpt(); | |
echo '<p>' . trunc($excerpt, 15) . '...</p>';?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment