rdusnr

Untitled

May 25th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1.  
  2. if ( ! function_exists( 'kleo_excerpt' ) ) {
  3.     function kleo_excerpt( $limit = 80, $words = true ) {
  4.  
  5.         $excerpt_initial = get_the_excerpt();
  6.         if( $excerpt_initial == '' ){
  7.             $excerpt_initial = get_the_content();
  8.         }
  9.         $excerpt_initial = preg_replace( '`\[[^\]]*\]`', '', $excerpt_initial );
  10.         $excerpt_initial = strip_tags( $excerpt_initial );
  11.  
  12.         if ( $words ) {
  13.             $excerpt = explode( ' ', $excerpt_initial, $limit );
  14.             if ( count( $excerpt ) >= $limit ) {
  15.                 array_pop( $excerpt );
  16.                 $excerpt = implode( " ", $excerpt ) . '...';
  17.             } else {
  18.                 $excerpt = implode( " ", $excerpt ) . '';
  19.             }
  20.         } else {
  21.             $excerpt = $excerpt_initial;
  22.             $excerpt = substr( $excerpt, 0, $limit ) . ( strlen( $excerpt ) > $limit ? '...' : '' );
  23.         }
  24.  
  25.         return '<p>' . $excerpt . '</p>';
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment