Advertisement
Guest User

code

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