UTF8 Excerpt Problem

Home Forums Iconic One Pro Support UTF8 Excerpt Problem

This topic contains 1 reply, has 2 voices, and was last updated by  Themonic-Support 6 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4850

    yiranguo
    Participant

    The Excerpt doesn’t work well because my language of content is Chinese. May I know how to solve this problem, please?

    My website: https://guoyiran.cn/

    #4851

    Themonic-Support
    Keymaster

    One of the easy solution is to install this plugin

    https://wordpress.org/plugins/wp-utf8-excerpt/

    Just make sure that images in the article are after first paragraph else it will show both images along with excerpt.

    — Perfect solution —

    Check out these lines 68-71 of functions.php

    
    function themonic_excerpt_length( $length ) {
    	return 58;
    }
    add_filter( 'excerpt_length', 'themonic_excerpt_length', 999 );

    and replace the above lines with

    
    function iconic_one_pro_chinese_excerpt( $output ) {
    global $post;
    $chinese_output = preg_match_all("/\p{Han}+/u", $post->post_content, $matches);
    if($chinese_output) {
    $output = mb_substr( $output, 0, 180 ) . '… <span class="read-more"><a href="'. get_permalink($post->ID) . '">' . __( 'Read More', 'themonic' ) . ' &raquo;</a></span>';
    }
    return $output;
    }
    add_filter( 'get_the_excerpt', 'iconic_one_pro_chinese_excerpt' );

    sending the same to your email.

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

You must be logged in to reply to this topic.