WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[closed] %%Excerpt%% for Chinese Character (18 posts)

  1. David Pi
    Member
    Posted 2 years ago #

    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/

  2. David Pi
    Member
    Posted 2 years ago #

    Hello. Did anyone read this?

  3. tilpro
    Member
    Posted 2 years ago #

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

  4. Aahan Krish
    Member
    Posted 2 years ago #

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

  5. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

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

  6. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

    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 ) ),

    ?

  7. David Pi
    Member
    Posted 2 years ago #

    Hello. I've tried the code but it doesn't fix it. All the Chinese Characters became "?".

  8. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

    Hmm shit. Ok, looking at other options.

  9. Alexander Gieg
    Member
    Posted 2 years ago #

    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.

  10. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

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

  11. waitxd
    Member
    Posted 1 year ago #

    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.

  12. waitxd
    Member
    Posted 1 year ago #

    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.

  13. Roberto
    Member
    Posted 1 year ago #

    In croatian language with wp_html_excerpt problem is resolved :D ... thanks

  14. Yurys
    Member
    Posted 1 year ago #

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

  15. Gchatzop
    Member
    Posted 1 year ago #

    Thanx waitd!

  16. Jowy92
    Member
    Posted 1 year ago #

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

  17. ShokAIM
    Member
    Posted 1 year ago #

    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.

    finely, after searching 2 hours for a fix ! THX waitxd

  18. wpmubp
    Member
    Posted 1 year ago #

    This doesn't seem to be fixed on the latest version, so I guess people like me should modify plugin manually according to:

    http://wordpress.org/support/topic/plugin-wordpress-seo-by-yoast-excerpt-for-chinese-character?replies=17#post-3119509

    I hope Joost will fix this soon.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic