Advertisement
alchymyth

trim excerpt

Oct 30th, 2011
1,501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. function custom_wp_trim_excerpt($text) {
  2. $raw_excerpt = $text;
  3. if ( '' == $text ) {
  4. //Retrieve the post content.
  5. $text = get_the_content('');
  6.  
  7. //Delete all shortcode tags from the content.
  8. $text = strip_shortcodes( $text );
  9.  
  10. $text = apply_filters('the_content', $text);
  11. $text = str_replace(']]>', ']]>', $text);
  12.  
  13. $text = strip_tags($text, '<em><br><p>');
  14.  
  15. $excerpt_word_count = 130; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/
  16. $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
  17.  
  18. $excerpt_end = '<div class="excerpt-readmore"><a href="'. get_permalink($post->ID) . '">--read more</a></div>'; /*** MODIFY THIS. change the excerpt endind to something else.***/
  19. $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);
  20.  
  21. $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
  22. if ( count($words) > $excerpt_length ) {
  23. array_pop($words);
  24. $text = implode(' ', $words);
  25. $text = force_balance_tags($text) . $excerpt_more;
  26. } else {
  27. $text = implode(' ', $words);
  28. }
  29. }
  30. return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
  31. }
  32. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  33. add_filter('get_the_excerpt', 'custom_wp_trim_excerpt');
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement