Forum Replies Created

Viewing 1 replies (of 1 total)
  • LordAzriel

    (@lordazriel)

    If you use PHP > 5.3 you can make use of anonymous functions.

    In your functions.php:

    function custom_excerpt($new_length = 20, $new_more = '...') {
      add_filter('excerpt_length', function () use ($new_length) {
        return $new_length;
      }, 999);
      add_filter('excerpt_more', function () use ($new_more) {
        return $new_more;
      });
      $output = get_the_excerpt();
      $output = apply_filters('wptexturize', $output);
      $output = apply_filters('convert_chars', $output);
      $output = '<p>' . $output . '</p>';
      echo $output;
    }

    In your template:
    <?php custom_excerpt(40, 'moo') ?>

Viewing 1 replies (of 1 total)