Posted By

kristarella on 01/20/09


Tagged

words wordpress wordcount limit excerpt


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

nerdfiles
umang_nine
Bluewall
girliegeek
love
nerdsane
naeemnur


Limit WordPress excerpts


 / Published in: PHP
 

URL: http://wordpress.org/support/topic/227692

Thanks to LenK on the WP forums.

  1. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  2. add_filter('get_the_excerpt', 'custom_trim_excerpt');
  3.  
  4. function custom_trim_excerpt($text) { // Fakes an excerpt if needed
  5. global $post;
  6. if ( '' == $text ) {
  7. $text = get_the_content('');
  8. $text = apply_filters('the_content', $text);
  9. $text = str_replace(']]>', ']]>', $text);
  10. $text = strip_tags($text);
  11. $excerpt_length = x;
  12. $words = explode(' ', $text, $excerpt_length + 1);
  13. if (count($words) > $excerpt_length) {
  14. array_pop($words);
  15. array_push($words, '...');
  16. $text = implode(' ', $words);
  17. }
  18. }
  19. return $text;
  20. }

Report this snippet  

You need to login to post a comment.