Blog excerpt length – set number of characters not words

This topic has 6 replies, 3 voices, and was last updated 8 years, 8 months ago ago by Jack Richardson

  • Avatar: TimBozo
    TimBozo
    Participant
    April 5, 2016 at 13:55

    Hi,
    At the moment my blog excerpts are showing as the default 55 words, set by lines 690-713 in the theme-functions.php file. I’d like to set the excerpt length by number of characters (preferably to include spaces), rather than words – this is to ensure excerpt boxes are all of the same height. Please advise how to achieve this. Thank you in advance.
    Best wishes … Tim

    Please, contact administrator
    for this information.
    5 Answers
    Avatar: Eva
    Eva Kemp
    Support staff
    April 5, 2016 at 14:06

    Hello,

    Excerpts are shown the ones which you selected in posts editor adding “read more” tag http://storage4.static.itmages.com/i/16/0405/h_1459861316_6826319_b3d3191325.png .
    As you can see excerpts height is different because your images have different height.
    Try to use this code in Custom CSS for desktop section:

    article.post-grid .wp-picture img {
       height: 250px;
    }

    and change excerpt height moving “more” tag.

    Regards,
    Eva Kemp.

    Avatar: TimBozo
    TimBozo
    Participant
    April 5, 2016 at 15:03

    Hi, thanks for your quick reply once again,

    I’m happy with the different heights on the blog archive page, it’s on the homepage where I’d like the boxes to be of equal height. The only way I can see to do this is to limit the excerpt by number of characters. Is this doable please?

    Thanks … .Tim

    Avatar: Eva
    Eva Kemp
    Support staff
    April 5, 2016 at 16:12

    Hello,

    You can use this css code to align blocks in one line:

    .page-id-31 .vc_gitem_row {
        height: 360px;
    }

    Regards,
    Eva Kemp.

    Avatar: TimBozo
    TimBozo
    Participant
    April 6, 2016 at 11:53

    Sorry, but that’s still not what I need – I need to limit the length of the excerpt by the number of characters, not by the number of words … if possible?

    Any help would be very much appreciated. Thank you in advance, best wishes, Tim

    This is what is limiting it by words (55) at the moment, from theme-functions.php:

    if(!function_exists(‘et_excerpt’)) {
    function et_excerpt($text, $excerpt){
    if ($excerpt) return $excerpt;

    $text = strip_shortcodes( $text );

    $text = apply_filters(‘the_content’, $text);
    $text = str_replace(‘]]>’, ‘]]>’, $text);
    $text = strip_tags($text);
    $excerpt_length = apply_filters(‘excerpt_length’, 55);
    $excerpt_more = apply_filters(‘excerpt_more’, ‘ ‘ . ‘[…]’);
    $words = preg_split(“/[\n
    ]+/”, $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    if ( count($words) > $excerpt_length ) {
    array_pop($words);
    $text = implode(‘ ‘, $words);
    $text = $text . $excerpt_more;
    } else {
    $text = implode(‘ ‘, $words);
    }

    return apply_filters(‘wp_trim_excerpt’, $text, $excerpt);
    }
    }

    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    April 6, 2016 at 12:11

    Hello,

    Please take our apologies but there is no feature to limit length of the excerpt by the number of characters.

    Best regards,
    Jack Richardson.

  • Viewing 6 results - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.