Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save vishalbasnet23/5d0d203a0bc4e0532310 to your computer and use it in GitHub Desktop.

Select an option

Save vishalbasnet23/5d0d203a0bc4e0532310 to your computer and use it in GitHub Desktop.
Simple excerpt by word count WordPress
Usage:
<?php echo code_content( $limit ); ?>
<?php
function code_content($limit) {
$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(']]>', ']]&gt;', $content);
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment