SHARE
TWEET

Untitled

a guest Apr 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if( ! function_exists( 'pe_excerpt' ) ) {
  2.     /**
  3.      * [[Description]]
  4.      * @param  integer $len Excerpt length (words)
  5.      * @param  string $trim (...) cut sign
  6.      * @param  boolean $readmore Show readmore
  7.      */
  8.     function pe_excerpt($len = 15, $trim = '…', $readmore = false) {
  9.         if($len < 1) return; //if 0 -> disable excerpt
  10.         $limit = $len + 1;
  11.         $excerpt = strip_shortcodes(get_the_content());
  12.         $excerpt = explode(' ', $excerpt, $limit);
  13.         $num_words = count($excerpt);
  14.         if($num_words >= $len) {
  15.             $last_item = array_pop($excerpt);
  16.         }
  17.         else {
  18.             $trim = '';
  19.         }
  20.         $excerpt = implode(' ', $excerpt) . $trim;
  21.         if( $readmore === true ) {
  22.             $excerpt .= pe_read_more_link();
  23.         }
  24.         $excerpt = wp_strip_all_tags($excerpt);
  25.         echo $excerpt;
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top