Advertisement
alchymyth

do_shortcode in excerpt

Apr 16th, 2011
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  2. add_filter('get_the_excerpt', 'wp_trim_excerpt_do_shortcode');
  3.  
  4. function wp_trim_excerpt_do_shortcode($text) {
  5.  
  6.     $raw_excerpt = $text;
  7.     if ( '' == $text ) {
  8.         $text = get_the_content('');
  9.  
  10.         $text = do_shortcode( $text );
  11.  
  12.         $text = apply_filters('the_content', $text);
  13.         $text = str_replace(']]>', ']]>', $text);
  14.         $text = strip_tags($text);
  15.         $excerpt_length = apply_filters('excerpt_length', 55);
  16.         $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
  17.         $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
  18.         if ( count($words) > $excerpt_length ) {
  19.             array_pop($words);
  20.             $text = implode(' ', $words);
  21.             $text = $text . $excerpt_more;
  22.         } else {
  23.             $text = implode(' ', $words);
  24.         }
  25.     }
  26.     return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement