Website owners often rely on bloated plugins to handle simple tasks that could be solved more efficiently. Slug transliteration, which changes non-Latin letters into Latin ones for better-looking URLs, is a good example of this.
The benefit of readable URLs goes beyond looks. It helps to avoid broken links caused by browsers or websites that cannot handle special characters properly. This does not require an additional plugin - just a simple code snippet.
Why Use Latin Characters Only?
URLs rely on ASCII characters, covering just basic Latin letters, digits, and some symbols. Using characters outside this set, like accented letters or different alphabets, needs special handling.
Even though browsers and servers today handle these characters, they turn them into codes with percent signs and numbers. This makes the URLs look complicated and difficult to understand.
The Benefits of Using Latin Characters in URLs
Transliteration takes special characters and turns them into similar Latin letters. This makes URLs more readable, which improves their visibility on search engines and social media.
Sticking to Latin characters in URLs avoids issues with email clients, content networks, and old browsers. This approach also reduces errors in server logs and tracking caused by non-standard characters.
Google Search Central Guidelines
According to Google Search Central, URLs should match the language of your visitors. When URLs contain characters outside the Latin alphabet, it can get tricky.
Transliteration helps by converting those characters into Latin ones. This makes URLs easier to read and more relevant to the audience, especially for languages using different alphabets.
The Special Characters in Native Slugs
WordPress sanitizes slugs by removing spaces, turning letters into lowercase, and swapping special characters with dashes. Still, it struggles with letters that do not belong to the English alphabet.
The challenge is with non-ASCII characters from languages like Polish, Russian, German, Turkish, or any language with accents, umlauts, or completely different alphabets often remain in the slug unless properly transliterated.
These often stay in the slug unless transliterated properly. This can create URLs that some browsers or third-party tools find hard to handle.
The "No Plugin" Solution
Plugins are useful, but sometimes a simple code solution does the job better. With one short function, you can handle slug transliteration across WordPress without adding new dependencies.
The method uses a standard WordPress filter that automatically applies to new slugs. If you have a child theme configured, there is no need to install anything extra.
Once added, this code rewrites slugs when a new post, page, or taxonomy term is created.
Transliterate WordPress Slugs
The following code covers transliteration of WordPress slugs for six languages.
- Russian
- Bulgarian
- Serbian
- Ukrainian
- Greek
- Arabic
This function changes the specified characters across all listed languages. You can adjust the character map to fit the alphabet used in your project.
Extra Considerations and Limitations
Using custom transliteration without a plugin offers more control, but it might need some fine-tuning. The code shared here does not cover every language or character.
If your site handles different alphabets or uncommon letters, you may have to update it. Otherwise, some characters might remain untranslated, which can cause confusing or broken URLs.
Keep in mind that this code only affects slugs created or updated after implementing the code. Older slugs will stay the same unless you regenerate them to keep URLs consistent.
Leave a Reply