Advertisement
alchymyth

custom excerpt - readmore

Aug 27th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function improved_trim_excerpt($text) {
  2.  
  3. global $post;
  4.  
  5. if ( '' == $text ) {
  6.  
  7. $text = get_the_content('');
  8.  
  9. $text = apply_filters('the_content', $text);
  10.  
  11. $text = str_replace('\]\]\>', ']]>', $text);
  12.  
  13. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  14.  
  15. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  16.  
  17. $text = strip_tags($text, '<p>, <strong>, <a>, <br>');
  18.  
  19. $excerpt_length = 55;
  20.  
  21. $words = explode(' ', $text, $excerpt_length + 1);
  22.  
  23. if (count($words)> $excerpt_length) {
  24.  
  25. array_pop($words);
  26.  
  27. //add the read-more link to the excerpt
  28. global $post;
  29. $read_more = '<a href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
  30.  
  31. array_push($words, $read_more); //edit
  32.  
  33. $text = implode(' ', $words);
  34.  
  35. }
  36.  
  37. }
  38.  
  39. return $text;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement