rdusnr

Untitled

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