WordPress slug issue with non-latin characters

I’m using permalinks in WP as: domain.com/category/post_name

The issue is that post names have non-latin characters such as chinese, hebrew, and arabic. So it encodes them to something like: %20%18%6b%20 therefore it counts every symbol’s character as an actual character, ending up with 3x times more length that it truncates some very short slugs.

Read More

How to fix that? Or at least how to extend the length limit at least? I’ve tried to extend the length of the database field “post_name” from 200 to 500, But it’s still truncating short.

Related posts

Leave a Reply

5 comments

  1. You can change post_name by appling the filters for sanitize_title
    Short example:

    add_filter('sanitize_title', 'sanitize_title_custom', 10, 3);
    function sanitize_title_custom($title, $raw_title, $context){
        // do some proccesing with title or raw_title
        // assign new result to $title ($title = str_replace(" ","-", $raw_title);// as example )
        return $title;
    }
    

    but, be careful… bad sanitizing can be security risk… sql injections etc…

  2. WordPress should not be encoding your post slugs like that. I use utf8 characters in titles and slugs all the time for clients. It works fine.

    Are you sure that your database table’s charset is utf8? If so, has it been overridden for any of the columns? Also check wp-config.php for define('DB_CHARSET', 'utf8');

    I would also disable any plugins and test your permalinks again. Maybe one of your plugins is screwing with your post slugs.

  3. This is a common situation that frustrates me too.

    Check this plugin. Clean Trunks

    1. You can set the the maximum url length on plugin configuration page.
      (Default: 35 characters.)
    2. Also you have the option to edit stopword list supplied.

    Hope this will help. Cheers !!!

  4. For non English URL:
    I’m using IIS with fcgi and I found the solution for non english slug in different places on the web:
    for Hebrew: here
    for more info about IIS7 URL Rewrite and Symbols : here
    generally except the IIS configuration for pretty url you need to add to the end of the wp-config.php:

        if (isset($_SERVER['UNENCODED_URL']))
    $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
    

    here you will find more about UNENCODED_URL