Guest User

Custom Excerpt - croque-pixel.com

a guest
Dec 13th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. // Multiple Excerpt
  2. function croque_pixel_excerpt( $charlength, $excerpt = false, $excerpt_more = true ) {
  3.  
  4.     if( ! $excerpt) {
  5.         $excerpt = get_the_excerpt();
  6.     }
  7.  
  8.     // Remove shortcodes for excerpt
  9.     $excerpt = strip_shortcodes( $excerpt );
  10.     $charlength++;
  11.  
  12.     if( strlen( $excerpt ) > $charlength ) {
  13.         $subex   = substr( $excerpt, 0, $charlength-5 );
  14.         $exwords = explode(" ",$subex);
  15.         $excut   = -( strlen( $exwords[count( $exwords )-1] ) );
  16.         if( $excut < 0 ) {
  17.             $new_excerpt = substr( $subex, 0, $excut );
  18.         } else {
  19.             $new_excerpt = $subex;
  20.         }
  21.         if( true == $excerpt_more ) {
  22.             $new_excerpt .= "...";
  23.         }
  24.     } else {
  25.         $new_excerpt = $excerpt;
  26.     }
  27.  
  28.     return $new_excerpt;
  29. }
Add Comment
Please, Sign In to add comment