Skip to content

Instantly share code, notes, and snippets.

@sauliuz
Created April 2, 2013 13:49
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 sauliuz/5292342 to your computer and use it in GitHub Desktop.
Save sauliuz/5292342 to your computer and use it in GitHub Desktop.
Show specific number of words in WordPress post content
<?php
// This code can be used directly in the WP loop
// But neater implementation would be to implement it
// Into WordPress theme functions.php file
// instead of using the_content() funcion
// we use new WordPress function (>3.0) to trim content
// to specific number of words
$content = get_the_content();
//$content = apply_filters('the_content', $content);
//$content = str_replace(']]>', ']]&gt;', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = wp_trim_words($content, 80, "...");
echo $content;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment