• devmania

    (@devmania)


    Hello,

    I’ve encountered an issue with URL encoding for post names in WordPress. The current process of URL encoding before saving in the database seems to result in insufficient field size, especially for some languages like Russian and Arabic. The URL encoded format becomes overly lengthy, accommodating only 3 to 4 smal words in these languages and truncating the rest of the title which makes it unreadable and bad for SEO.

    The sanitization process involves various actions, including the use of utf8_uri_encode. I’m hesitant to modify the code directly to avoid potential errors or vulnerabilities. I’m seeking advice on alternative solutions to address this issue without compromising the code’s integrity. Any suggestions would be greatly appreciated.

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m afraid the slug length limitation is necessary to maintain full compatibility across the entire internet. When URL encoded, each Cyrillic letter takes up 6 character’s worth of length. WP limits slugs to 200 characters to help ensure the total URL length does not exceed the standard for HTTP requests. Thus your Russian slugs are typically limited to 33 letters. I’m sorry to say there is no way I can see to cleanly override this limitation. Be glad you’re not Vietnamese whose encoding takes up twice as much length, limiting them to 16 characters! I know, that’s of little solace for you. Just saying it could be worse.

    Thread Starter devmania

    (@devmania)

    Thank you for your reply.

    I wonder why the URL encoding process was added inside the sanitization process.

    I think it’s possible to save and retrieve UTF-8 characters like Russian and Vietnamese?letters from the database in their original format.

    Moderator bcworkz

    (@bcworkz)

    Yes, I think it would be possible to reinstate the non-encoded URL. The URL would not be 100% standards compliant, but I believe non-encoded URLs would only be a problem for those using very old browsers.

    Maybe try using the “wp_unique_post_slug” filter and running the passed slug through urldecode(). Unverified, but I think it’ll work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post names (slugs) getting insufficient’ is closed to new replies.