Skip to content

Instantly share code, notes, and snippets.

@mrzlodey
Created July 30, 2015 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrzlodey/d7165cd4f054a5763946 to your computer and use it in GitHub Desktop.
Save mrzlodey/d7165cd4f054a5763946 to your computer and use it in GitHub Desktop.
<?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