Limit WordPress excerpts


/ Published in: PHP
Save to your folder(s)

Thanks to LenK on the WP forums.


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.