Advertisement
aadf

excerpt functions

Sep 4th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. /*============================================================
  2. Add Custom Excerpt Legnth
  3. ============================================================*/
  4. function custom_excerpt($new_length = 15, $new_more = 'Read more . . .') {
  5.  
  6.   // use the variable passed from $new_length as the length of the excerpt
  7.   add_filter('excerpt_length', function () use ($new_length) {
  8.     return $new_length;
  9.   }, 999);
  10.  
  11.   // determine what comes at the end of the excerpt (in this case ...)
  12.   add_filter('excerpt_more', function () use ($new_more) {
  13.     return $new_more;
  14.   });
  15.  
  16.   // generate the current excerpt
  17.   $output = get_the_excerpt();
  18.  
  19.   // use wptexturize to basically sanitize the excerpt
  20.   $output = apply_filters('wptexturize', $output);
  21.  
  22.   // convert_chars to remove metadata tags and convert others to unicode
  23.   $output = apply_filters('convert_chars', $output);
  24.  
  25.   // wrap it back up in p tags
  26.  
  27.   // the above line may not be needed depending on the status of wpautop
  28.  
  29.   // echo that sucker
  30.   echo $output;
  31. }
  32.  
  33. /*============================================================
  34. Add Read More Link To Excerpt
  35. ============================================================*/
  36. function new_excerpt_more($more) {
  37.     global $post;
  38.     return '<a href="'. get_permalink($post->ID) . '"> Read more . . .</a>';
  39. }
  40. add_filter('excerpt_more', 'new_excerpt_more');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement