Share Pastebin
Guest
Public paste!

Hench / WP the_excerpt hack

By: a guest | Mar 4th, 2010 | Syntax: PHP | Size: 0.94 KB | Hits: 664 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. function improved_trim_excerpt($text) {
  2.         global $post;
  3.         if ( '' == $text ) {
  4.                 $text = get_the_content('');
  5.                 $text = apply_filters('the_content', $text);
  6.                 $text = str_replace(']]>', ']]>', $text);
  7.                 $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  8.                 $text = strip_tags($text, '<p>,<strong>,<br />');
  9.                 $excerpt_length = 35;
  10.                 $words = explode(' ', $text, $excerpt_length + 1);
  11.                 if (count($words)> $excerpt_length) {
  12.                         array_pop($words);
  13.                         array_push($words, '&hellip; <p><a href="'. get_permalink($post->ID) . '">' . 'Read more&hellip;' . '</a></p>');
  14.                         $text = implode(' ', $words);
  15.                 }
  16.         }
  17.         return $text;
  18. }
  19.  
  20.  
  21. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  22. add_filter('get_the_excerpt', 'improved_trim_excerpt');
  23.  
  24. function new_excerpt_more($more) {
  25.         return '&hellip; <p><a href="'. get_permalink($post->ID) . '">' . 'Read more&hellip;' . '</a></p>';
  26. }
  27. add_filter('excerpt_more', 'new_excerpt_more');