We've some Arabic websites running on WordPress, and use Arabic slugs in the posts' URLs.

You know that post slug is stored in the post_name column in wp_posts table, and the default length of this column is 200 characters, which is not enough for Arabic slugs that are being encoded before being stored in this column. For that, we changed the length of this column to 1000 characters to hold the long encoded slugs that we have.

The issue, when we update the WordPress code to a major update, it trims this column back to 200 characters, and this breaks the posts' URLs. This happens if you login for the first time after the update to the CMS or do a Network Upgrade that is prompted after each major update.

Is there any way to prevent WordPress from touching the tables' structure?


I don't have a definitive answer for you, but I had a quick look at some of the upgrade code and noticed that a very old upgrade function rewrites the post_name using the sanitize_title function, and that calls sanitize_title_with_dashes, and that contains this bit of code:

  if ( seems_utf8( $title ) ) {
    if ( function_exists( 'mb_strtolower' ) ) {
      $title = mb_strtolower( $title, 'UTF-8' );
    $title = utf8_uri_encode( $title, 200 );

Note that this is pretty interesting because only if the function mb_strtolower is not available will this code cause the string to become truncated to 200 characters!

You could do a quick check on your system to see if you have the PHP multibyte string extension installed, because if you don't, then sanitize title will truncate your titles, and so maybe you can solve your problem by installed the PHP multibyte extension.

To check if that's the case, have a look at phpinfo();, or just run this somewhere directly on your server:

if ( function_exists( 'mb_strtolower' ) ) {
   echo "yes mb strings installed";
} else {
   echo "no mb strings not installed";

Please note: There's too much code for me to validate that this is definitely what's happening in your case. Someone else may have a definite answer. The '200' value which aligns perfectly with what's happening for you seems like a good indiciation that this could be the issue, but I didn't find any specific place where this is called on every single upgrade.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.