Support » Plugin: Yoast SEO » [Plugin: WordPress SEO by Yoast] %%Excerpt%% for Chinese Character

  • Hello.
    The plugin cannot auto generate %%Excerpt%% for Chinese Character. This is because it use substr which don’t support UTF-8.

    This can be fixed by changing /wordpress-seo/inc/wpseo-functions.php:

    Search:
    '%%excerpt%%' => ( !empty($r->post_excerpt) ) ? strip_tags( $r->post_excerpt ) : substr( strip_shortcodes( strip_tags( $r->post_content ) ), 0, 155 ),

    Replace with:
    '%%excerpt%%' => ( !empty($r->post_excerpt) ) ? strip_tags( $r->post_excerpt ) : mb_substr( strip_shortcodes( strip_tags( $r->post_content ) ), 0, 155,'utf-8' ),

    Each time I upgrade the plugin, I have to do it manually. Would you fix it? Thanks.

    Regards,
    David Pi

    http://wordpress.org/extend/plugins/wordpress-seo/

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter David Pi

    (@liberty-pi)

    Hello. Did anyone read this?

    It’s not why you posted, but it helped me in a problem I was having trouble solving. So yes, I read it.

    hey David, why don’t you tweet @yoast and let him know directly? 🙂 And don’t forget to mark this thread as resolved.

    Plugin Contributor Joost de Valk

    (@joostdevalk)

    Unfortunately mb_substr is not a default function in PHP, so I cannot rely on it. Let me figure out another solution.

    Plugin Contributor Joost de Valk

    (@joostdevalk)

    Does this fix it:

    '%%excerpt%%' => ( !empty( $r->post_excerpt ) ) ? strip_tags( $r->post_excerpt ) : utf8_encode( substr( strip_shortcodes( strip_tags( utf8_decode( $r->post_content ) ) ), 0, 155 ) ),

    ?

    Thread Starter David Pi

    (@liberty-pi)

    Hello. I’ve tried the code but it doesn’t fix it. All the Chinese Characters became “?”.

    Plugin Contributor Joost de Valk

    (@joostdevalk)

    Hmm shit. Ok, looking at other options.

    I’ve seen other plugins test for the existence of the mb_ version of a function and if present use that, otherwise use the normal one. This way it becomes a matter of adding to the plugin description something to the effect that for full CJK support mbstring is required, and maybe to the admin panel a warning informing a user with WPLANG == jp_JP etc. and no mbstring that he needs to contact his host for them to install this extension or support will be limited.

    Plugin Contributor Joost de Valk

    (@joostdevalk)

    Yeah I’ll probably have to fall back to something like that indeed.

    Unfortunately mb_substr is not a default function in PHP, so I cannot rely on it. Let me figure out another solution.

    Is this some kind of joke?

    WordPress widely uses mb_* functions and already has implementation for PHP functions that either missing from older PHP versions or not included by default in \wp-includes\compat.php

    So, please use the code above.

    Or, alternatively, you can use wp_html_excerpt:
    '%%excerpt%%' => (!empty($r->post_excerpt)) ? strip_tags($r->post_excerpt) : wp_html_excerpt(strip_shortcodes($r->post_content),155),
    It would be more correct, because essentially removes part of an entity at the end of string.

    In croatian language with wp_html_excerpt problem is resolved 😀 … thanks

    Thank you. Had the same problem with Russian characters. Your post helped 🙂

    Thanx waitd!

    Always the same probleme with 1.2.8.3 the € isn’t displayed. Hope the next relase will fix that.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Plugin: WordPress SEO by Yoast] %%Excerpt%% for Chinese Character’ is closed to new replies.