Created
March 7, 2017 10:43
-
-
Save dimobelov/fc8952229668a50c65be3a055652e4f5 to your computer and use it in GitHub Desktop.
Функция за автоматична транслитерация от кирилица към латиница на адресите в Wordpress
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
function cyr_sanitize_title($title) { | |
global $wpdb; | |
$iso9_table = array( | |
'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', | |
'Д' => 'D', 'Е' => 'E', 'Ж' => 'J', 'З' => 'Z', | |
'И' => 'I', 'Й' => 'Y', 'К' => 'K', 'Л' => 'L', | |
'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', | |
'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', | |
'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'CH', | |
'Ш' => 'SH', 'Щ' => 'SHT', 'Ъ' => 'A', 'Ь' => 'Y', | |
'Ю' => 'YU', 'Я' => 'YA', | |
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', | |
'д' => 'd', 'е' => 'e', 'ж' => 'j', 'з' => 'z', | |
'и' => 'i', 'й' => 'y', 'к' => 'k', 'л' => 'l', | |
'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', | |
'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', | |
'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', | |
'ш' => 'sh', 'щ' => 'sht', 'ъ' => 'a', 'ь' => 'y', | |
'ю' => 'yu', 'я' => 'ya' | |
); | |
$title = strtr($title, apply_filters('ctl_table', $iso9_table)); | |
$title = preg_replace("/[^A-Za-z0-9'_\-\.]/", '-', $title); | |
$title = preg_replace('/\-+/', '-', $title); | |
$title = preg_replace('/^-+/', '', $title); | |
$title = preg_replace('/-+$/', '', $title); | |
return $title; | |
} | |
add_filter('sanitize_title', 'cyr_sanitize_title', 9); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment