Created
July 30, 2015 11:26
-
-
Save mrzlodey/d7165cd4f054a5763946 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
Plugin Name: Transliteration URL | |
Plugin URI: https://gist.github.com/mrzlodey/d7165cd4f054a5763946 | |
Description: Convert cyrillic characters in WordPress permalinks and loaded files to latin characters. | |
Author: SK | |
Version: 1.0.0 | |
Author URI: http://codebeer.ru/ | |
*/ | |
function transliterate_url( $text ) { | |
$text = mb_strtolower( $text, 'UTF-8' ); | |
$symbol_table = array('а' => 'a', 'б' => 'b', 'в' => 'v', | |
'г' => 'g', 'д' => 'd', 'е' => 'e', | |
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', | |
'и' => 'i', 'й' => 'j', 'к' => 'k', | |
'л' => 'l', 'м' => 'm', 'н' => 'n', | |
'о' => 'o', 'п' => 'p', 'р' => 'r', | |
'с' => 's', 'т' => 't', 'у' => 'u', | |
'ф' => 'f', 'х' => 'h', 'ц' => 'c', | |
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shh', | |
'ъ' => "", 'ы' => 'y', 'ь' => "", | |
'э' => 'e', 'ю' => 'yu', 'я' => 'ya'); | |
$text = strtr( $text, $symbol_table ); | |
return $text; | |
} | |
add_filter( 'sanitize_title', 'transliterate_url', 1 ); | |
add_filter( 'sanitize_file_name', 'transliterate_url', 1 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment