Created
January 10, 2011 04:18
-
-
Save kayue/772349 to your computer and use it in GitHub Desktop.
Get trimmed excerpt (by word) in WordPress
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 get_trimmed_excerpt($maxChars = 160, $appendingString = '...', $default_excerpt = "Default page description.") | |
{ | |
if( !is_single() && !is_page() ) | |
return $default_excerpt; | |
the_post(); | |
$content = substr(get_the_excerpt(), 0, $maxChars); | |
$content = strip_tags($content); | |
$pos = strrpos($content, " "); | |
if ($pos > 0) { | |
$content = substr($content, 0, $pos); | |
} | |
$result = $content.$appendingString; | |
rewind_posts(); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment