Viewing 1 replies (of 1 total)
  • Thread Starter grard

    (@grard)

    I have solved this issue by writing two functions and adding them to functions.php:

    function my_post_length($text = null) {
    $text = trim( strip_tags( get_the_content() ) );
    $word_number = preg_match_all( ‘~\s+~’, “$text “, $m );
    return $word_number;
    }

    add_filter( ‘the_excerpt’, ‘my_trim_excerpt’ );

    function my_trim_excerpt( $excerpt )
    {
    $content = apply_filters( ‘the_content’, get_the_content() );
    if (my_post_length() < 34) {
    $lastSpacePosition = strrpos($excerpt, ‘ ‘);
    $excerpt = substr($excerpt, 0, $lastSpacePosition);
    return $excerpt;
    }
    else return $excerpt;
    }

    You just have to set your actual excerpt length. In my case it’s =34.

Viewing 1 replies (of 1 total)

The topic ‘Counters displayed in excerpt’ is closed to new replies.