Skip to content

Instantly share code, notes, and snippets.

@rezzz-dev
Created April 28, 2013 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezzz-dev/5476979 to your computer and use it in GitHub Desktop.
Save rezzz-dev/5476979 to your computer and use it in GitHub Desktop.
Snippet: WP: Limit Content by X Words
function jr_limit_content($limit, $thecontent = "") {
if ($thecontent) {
$content = explode(' ', $thecontent, $limit);
}
else {
$content = explode(' ', get_the_content(), $limit);
}
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return strip_tags($content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment