Prevent changing the length of post_name column on WordPress Update

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.

Leave a Comment