Skip to content

Instantly share code, notes, and snippets.

@clarklab
Created March 30, 2017 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarklab/b4af33eaa4fcdb87f4a13ae98061a4c9 to your computer and use it in GitHub Desktop.
Save clarklab/b4af33eaa4fcdb87f4a13ae98061a4c9 to your computer and use it in GitHub Desktop.
Get first X words of WordPress post
// toss this in your functions.php (or elsewhere)
function get_shorty($count = 15){
global $post;
$str = get_the_content();
$str = implode(' ', array_slice(explode(' ', $str), 0, $count));
return $str.'...';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment