Created
April 2, 2013 13:49
-
-
Save sauliuz/5292342 to your computer and use it in GitHub Desktop.
Show specific number of words in WordPress post content
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 | |
// 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(']]>', ']]>', $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