New Landing How can we help? Themeforest Theme Support Supreme Two different excerpt lengths ?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Posted in: Supreme
  • #86913
    thedao
    Member
    Post count: 2

    Hello,
    I’ve been trying to reach that with no success.
    Could it be possible to have two different excerpt lengths?
    I’ve been trying this code but something goes wrong…

    In my 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 my template:

    <?php custom_excerpt(40, 'moo') ?>

    #86959
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    I am not sure about your code that why is it not working ? You can use another code:

    function excerpt($limit) {
     $excerpt = explode(' ', get_the_excerpt(), $limit);
     if (count($excerpt)>=$limit) {
     array_pop($excerpt);
     $excerpt = implode(" ",$excerpt).'...';
     } else {
     $excerpt = implode(" ",$excerpt);
     }
     $excerpt = preg_replace('<code>[[^]]*]</code>','',$excerpt);
     return $excerpt;
    }

    Example:-
    <?php echo excerpt(25); ?>
    Thanks

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register