• Resolved nemci7v

    (@nemci7v)


    I’m using the following excerpt filter but it limits the post length by words. How can I put a limit on characters? Like Twitter. I can;t find any documentation in Codex.

    function new_excerpt_length($length) {
    	return 20;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
Viewing 10 replies - 16 through 25 (of 25 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Or use this to return the excerpt in a paragraph:
    return apply_filters('the_content', $excerpt);

    seanjacob, no matter what number I set, your script will not display more than 64 characters.

    Pereira

    (@marcosmyara)

    It seems like “.$permalink.” is calling the actual url of the page where i’m at, and not the page of the single post.

    Is it only me? When i click “more” the page just reloads.

    seanjacob

    (@seanjacob)

    $permalink = get_permalink($post->ID);

    Try adding this to the top of the function.

    seanjacob

    (@seanjacob)

    Use this function if you’re planning on using it more than once with a different amount of characters.

    function get_excerpt($count){
      $permalink = get_permalink($post->ID);
      $excerpt = get_the_content();
      $excerpt = strip_tags($excerpt);
      $excerpt = substr($excerpt, 0, $count);
      $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
      $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
      return $excerpt;
    }

    Call the function plus the amount of characters –

    <?php echo get_excerpt(125); ?>

    Pereira

    (@marcosmyara)

    cheers!!

    Been trying to figure this out: Is there a way to use this code, creating a character limit, without truncating the last word? (I would still want the read more ellipses.)

    Any help would be appreciated!

    seanjacob

    (@seanjacob)

    Without the truncating –

    function get_excerpt($count){
      $permalink = get_permalink($post->ID);
      $excerpt = get_the_content();
      $excerpt = strip_tags($excerpt);
      $excerpt = substr($excerpt, 0, $count);
      $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
      return $excerpt;
    }

    Thank you, seanjacob!…I’ll give it a shot later today! ??

    seanjacob

    (@seanjacob)

    Haha nice one! No problem.

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘Limit excerpt length by characters’ is closed to new replies.