Site logo

Archived topic

Blog setting "Excerpt word count" doesn't work on other language.

5 replies · Started by Kin on June 1, 2020

Viewing posts 1–6 of 6

Hi all,
I just brought your premium plan a week ago.
Most of the things are good, I am satisfy about that.

However, there is one thing I am so confuse , which is the setting under Customizing > Layout > Blog > Excerpt word count, the default value of "Excerpt word count" should be 20.
There looks nice on your demo page, however, when I already wrote the article with Transitional Chinese version, it seems doesn't count the words correctly. It looks terribly long chinese text display even if I set the "Excerpt word count" to 5-10.

Would you please help or provide some solution can solve this problem?
I am appreciated about this.

Hi, Thank you for your information provided,
I followed your link and fixed the Excerpt word count problem.
However,it seems that another issue existed, the problem is the "read more" button only disappear on chinese language article,the default english article remain normal, please check this
Image

I am look forward to hearing from your.
Thanks a lot.

Try this function:

function dez_filter_chinese_excerpt( $output ) {
    global $post;
    //check if its chinese character input
    $chinese_output = preg_match_all("/\p{Han}+/u", $post->post_content, $matches);
    if($chinese_output) {
        $output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>',
            mb_substr( $output, 0, 50 ) . '...',
            get_permalink(),
            __( 'Read more', 'generatepress' )
        );
    }
    return $output;
}
add_filter( 'get_the_excerpt', 'dez_filter_chinese_excerpt' );

Thank you for your help,
The problem has been solved.

This archived topic is closed to new replies.