Advertisement
miriamdepaula

WordPress: Customizando o excerpt

Jul 3rd, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2. function custom_wp_trim_excerpt($text) {
  3. $raw_excerpt = $text;
  4. if ( '' == $text ) {
  5.     //Retrieve the post content.
  6.     $text = get_the_content('');
  7.  
  8.     //Delete all shortcode tags from the content.
  9.     $text = strip_shortcodes( $text );
  10.  
  11.     $text = apply_filters('the_content', $text);
  12.     $text = str_replace(']]>', ']]&gt;', $text);
  13.  
  14.     $allowed_tags = ''; /*** MODIFY THIS. Add the allowed HTML tags separated by a comma.***/
  15.     $text = strip_tags($text, $allowed_tags);
  16.  
  17.     $excerpt_word_count = 55; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/
  18.     $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
  19.  
  20.     $excerpt_end = '[...]'; /*** MODIFY THIS. change the excerpt endind to something else.***/
  21.     $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);
  22.  
  23.     $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
  24.     if ( count($words) > $excerpt_length ) {
  25.         array_pop($words);
  26.         $text = implode(' ', $words);
  27.         $text = $text . $excerpt_more;
  28.     } else {
  29.         $text = implode(' ', $words);
  30.     }
  31. }
  32. return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
  33. }
  34. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  35. add_filter('get_the_excerpt', 'custom_wp_trim_excerpt');
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement