Skip to content

Instantly share code, notes, and snippets.

@davidsneighbour
Last active April 26, 2020 17:04
Show Gist options
  • Save davidsneighbour/9c6e1eb93d110b4bf59b to your computer and use it in GitHub Desktop.
Save davidsneighbour/9c6e1eb93d110b4bf59b to your computer and use it in GitHub Desktop.
Umlauts for German WordPress slug - add these lines to your functions.php and forget it.
<?php
add_filter('sanitize_title', 'dnb_transliterate_slug', 5, 3);
function dnb_transliterate_slug($title, $raw_title = NULL, $context = 'query') {
// Hacky hook due to hacky core, see
// http://core.trac.wordpress.org/ticket/16905
if ($raw_title != NULL) {
$title = $raw_title; // undo remove_accents
}
$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); // redo remove_accents
}
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment