Created
July 30, 2025 20:04
-
-
Save maciejbis/a16ec1675dc04dd0da60e7e33256fa00 to your computer and use it in GitHub Desktop.
Transliterate WordPress slugs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pm_multilang_transliterate( $slug ) { | |
$tr = array( | |
// Russian | |
"А"=>"a", "Б"=>"b", "В"=>"v", "Г"=>"g", "Д"=>"d", "Е"=>"e", "Ё"=>"yo", "Ж"=>"zh", "З"=>"z", "И"=>"i", | |
"Й"=>"j", "К"=>"k", "Л"=>"l", "М"=>"m", "Н"=>"n", "О"=>"o", "П"=>"p", "Р"=>"r", "С"=>"s", "Т"=>"t", | |
"У"=>"u", "Ф"=>"f", "Х"=>"kh", "Ц"=>"ts", "Ч"=>"ch", "Ш"=>"sh", "Щ"=>"sch", "Ъ"=>"", "Ы"=>"y", "Ь"=>"", | |
"Э"=>"e", "Ю"=>"yu", "Я"=>"ya", "а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ё"=>"yo", | |
"ж"=>"zh", "з"=>"z", "и"=>"i", "й"=>"j", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", | |
"р"=>"r", "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"kh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", "щ"=>"sch", | |
"ъ"=>"", "ы"=>"y", "ь"=>"", "э"=>"e", "ю"=>"yu", "я"=>"ya", | |
// Bulgarian | |
"щ"=>"sht", "ъ"=>"a", "ь"=>"y", "ю"=>"yu", "я"=>"ya", | |
"Щ"=>"sht", "Ъ"=>"a", "Ь"=>"y", "Ю"=>"yu", "Я"=>"ya", | |
// Serbian | |
"Ђ"=>"dj", "ђ"=>"dj", "Љ"=>"lj", "љ"=>"lj", "Њ"=>"nj", "њ"=>"nj", | |
"Ћ"=>"c", "ћ"=>"c", "Џ"=>"dz", "џ"=>"dz", "Ш"=>"s", "ш"=>"s", "Ч"=>"c", "ч"=>"c", | |
// Ukrainian | |
"Є"=>"ye", "І"=>"i", "Ї"=>"yi", "Ґ"=>"g", "є"=>"ie", "і"=>"i", "ї"=>"i", "ґ"=>"g", | |
// Greek | |
"Α"=>"a", "Ά"=>"a", "Β"=>"v", "Γ"=>"g", "Δ"=>"d", "Ε"=>"e", "Έ"=>"e", "Ζ"=>"z", "Η"=>"i", "Ή"=>"i", | |
"Θ"=>"th", "Ι"=>"i", "Ί"=>"i", "Ϊ"=>"i", "ΐ"=>"", "Κ"=>"k", "Λ"=>"l", "Μ"=>"m", "Ν"=>"n", "Ξ"=>"x", | |
"Ο"=>"o", "Ό"=>"o", "Π"=>"p", "Ρ"=>"r", "Σ"=>"s", "Τ"=>"t", "Υ"=>"y", "Ύ"=>"y", "Ϋ"=>"y", "ΰ"=>"y", | |
"Φ"=>"f", "Χ"=>"ch", "Ψ"=>"ps", "Ω"=>"o", "Ώ"=>"o", "α"=>"a", "ά"=>"a", "β"=>"v", "γ"=>"g", "δ"=>"d", | |
"ε"=>"e", "έ"=>"e", "ζ"=>"z", "η"=>"i", "ή"=>"i", "θ"=>"th", "ι"=>"i", "ί"=>"i", "ϊ"=>"i", "κ"=>"k", | |
"λ"=>"l", "μ"=>"m", "ν"=>"n", "ξ"=>"x", "ο"=>"o", "ό"=>"o", "π"=>"p", "ρ"=>"r", "σ"=>"s", "ς"=>"s", | |
"τ"=>"t", "υ"=>"y", "ύ"=>"y", "ϋ"=>"y", "φ"=>"f", "χ"=>"ch", "ψ"=>"ps", "ω"=>"o", "ώ"=>"o", | |
// Arabic | |
"ا"=>"a", "ب"=>"b", "ت"=>"t", "ث"=>"th", "ج"=>"j", "ح"=>"h", "خ"=>"kh", "د"=>"d", "ذ"=>"dh", "ر"=>"r", | |
"ز"=>"z", "س"=>"s", "ش"=>"sh", "ص"=>"s", "ض"=>"d", "ط"=>"t", "ظ"=>"z", "ع"=>"a", "غ"=>"gh", "ف"=>"f", | |
"ق"=>"q", "ك"=>"k", "ل"=>"l", "م"=>"m", "ن"=>"n", "ه"=>"h", "و"=>"w", "ي"=>"y", "ة"=>"h", "ء"=>"a", | |
"آ"=>"aa", "ؤ"=>"w", "ئ"=>"y", "أ"=>"a", "إ"=>"i" | |
); | |
return strtr($slug, $tr); | |
} | |
add_filter('sanitize_title', 'pm_multilang_transliterate', 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment