WordPress.org

Forums

Yoast SEO
[Plugin: WordPress SEO by Yoast] Chinese characters corrupted in description (8 posts)

  1. Derek Yang
    Member
    Posted 2 years ago #

    Hi Joost, I've been using your SEO plugin for quite a while with pleasure, but just noticed something wrong.

    It adds "description" automatically to all the posts, but, I don't know since which version, doesn't seem support Chinese characters, so many of my new posts are becoming ???????? in search engines, like this one:

    http://marketoversea.com/misc/market-economy-and-gift-economy.html

    I can't disable the plugin, that would change a lot of settings; however, I'm also unable to find any way of disabling this feature so it won't generate "description" automatically. I have to manually change that in my new posts.

    Would you please help, or let me know how to fix this, so it either stops generating description automatically, or supports Chinese characters?

    Much appreciated!

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

  2. anychanh
    Member
    Posted 2 years ago #

    Same here. It's also effect in Korean :(

  3. jrf
    Member
    Posted 2 years ago #

    Hiya,

    The problem was introduced in trac-revision 565588, I guess this would translate to WP SEO v 1.2.8.0 ?.

    The problem is in file wordpress-seo/inc/wpseo-functions.php, line 156:
    '%%excerpt%%' => ( !empty( $r->post_excerpt ) ) ? strip_tags( $r->post_excerpt ) : utf8_encode( substr( strip_shortcodes( strip_tags( utf8_decode( $r->post_content ) ) ), 0, 155 ) ),

    Here the utf8_encode and utf8_decode functions are used, however these functions will only work as expected if applied to a string in a latin characterset.

    In my opinion, the best fix to avoid breaking nearly all non-latin sites would be:
    '%%excerpt%%' => ( !empty( $r->post_excerpt ) ) ? strip_tags( $r->post_excerpt ) : ( (extension_loaded ( 'mbstring' ) === true ) ? mb_substr( strip_shortcodes( strip_tags( $r->post_content ) ), 0, 155, 'UTF-8' ) : substr( strip_shortcodes( strip_tags( utf8_decode( $r->post_content ) ) ), 0, 155 ) ),

    Hope this helps!

    Smile,
    Juliette

  4. Derek Yang
    Member
    Posted 2 years ago #

    That's working! Thanks Juliette, you're my hero!

  5. jrf
    Member
    Posted 2 years ago #

    You're very welcome.

    Could you please change the status of the topic back to unresolved though until the fix has been picked up by Yoast and included in the plugin for the next version ?

    Otherwise we'll have to keep changing the files manually which isn't really a solution.

  6. Derek Yang
    Member
    Posted 2 years ago #

    @ jrf Good point, changed back! Hope Y will see this soon!

  7. waitxd
    Member
    Posted 2 years ago #

    I think it's much better solution
    '%%excerpt%%' => (!empty($r->post_excerpt)) ? strip_tags($r->post_excerpt) : wp_html_excerpt(strip_shortcodes($r->post_content),155),

    wp_html_excerpt provide mb_functions fallback and remove part of html entity at the end of string

  8. jrf
    Member
    Posted 2 years ago #

    waitxd: nice one!

    I didn't know about the wp_html_excerpt() function. I have to say I find the name of the function very misleading (based on the name, I'd expect html to be returned, not a string completely stripped of html), but it looks very useful in this case.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Yoast SEO
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic