rdusnr

Untitled

Oct 24th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. if ( ! function_exists( 'kleo_excerpt' ) ) {
  2. function kleo_excerpt( $limit = 220, $words = true ) {
  3.  
  4. $from_content = false;
  5. $excerpt_initial = get_the_excerpt();
  6.  
  7. if( $excerpt_initial == '' ) {
  8. $excerpt_initial = get_the_content();
  9. $from_content = true;
  10. }
  11. $excerpt_initial = preg_replace( '`\[[^\]]*\]`', '', $excerpt_initial );
  12. $excerpt_initial = strip_tags( $excerpt_initial );
  13.  
  14. /* If we got it from get_the_content -> apply length restriction */
  15. if ( $from_content ) {
  16. $excerpt_length = apply_filters( 'excerpt_length', $limit );
  17. $excerpt_initial = wp_trim_words( $excerpt_initial, $excerpt_length, '' );
  18. }
  19.  
  20. if ( $words ) {
  21. $excerpt = explode( ' ', $excerpt_initial, $limit );
  22. if ( count( $excerpt ) >= $limit ) {
  23. array_pop( $excerpt );
  24. $excerpt = implode( " ", $excerpt ) . '...';
  25. } else {
  26. $excerpt = implode( " ", $excerpt ) . '';
  27. }
  28. } else {
  29. $excerpt = substr( $excerpt_initial, 0, $limit ) . ( strlen( $excerpt_initial ) > $limit ? '...' : '' );
  30. }
  31.  
  32. return '<p>' . $excerpt . '</p>';
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment