Skip to content

Instantly share code, notes, and snippets.

@cartorjo
Last active November 4, 2016 10:21
Show Gist options
  • Save cartorjo/e7f39c3279b87b7f8660e53f946a816e to your computer and use it in GitHub Desktop.
Save cartorjo/e7f39c3279b87b7f8660e53f946a816e to your computer and use it in GitHub Desktop.
I18N permalinks (converting common accentuated UTF-8 characters automatically with WordPress)
/**
* I18N permalinks (Czech, German)
*/
add_filter('sanitize_title', 'transliterate_slug', 5, 3);
function transliterate_slug($title, $raw_title = NULL, $context = 'query') {
if ($raw_title != NULL) {
$title = $raw_title;
}
// Czech
$title = str_replace('Č', 'c', $title);
$title = str_replace('č', 'c', $title);
$title = str_replace('Ď', 'd', $title);
$title = str_replace('ď', 'd', $title);
$title = str_replace('Ě', 'e', $title);
$title = str_replace('ě', 'e', $title);
$title = str_replace('Ň', 'n', $title);
$title = str_replace('ň', 'n', $title);
$title = str_replace('Ř', 'r', $title);
$title = str_replace('ř', 'r', $title);
$title = str_replace('Š', 's', $title);
$title = str_replace('š', 's', $title);
$title = str_replace('Ť', 't', $title);
$title = str_replace('ť', 't', $title);
$title = str_replace('Ů', 'u', $title);
$title = str_replace('ů', 'u', $title);
$title = str_replace('Ž', 'z', $title);
$title = str_replace('ž', 'z', $title);
// German
$title = str_replace('Ä', 'ae', $title);
$title = str_replace('ä', 'ae', $title);
$title = str_replace('Ö', 'oe', $title);
$title = str_replace('ö', 'oe', $title);
$title = str_replace('Ü', 'ue', $title);
$title = str_replace('ü', 'ue', $title);
$title = str_replace('ẞ', 'ss', $title);
$title = str_replace('ß', 'ss', $title);
if ($context == 'save') {
$title = remove_accents($title);
}
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment