Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Greeklish addresses for Greek titles

New posts, pages, products, categories and tags with Greek titles get addresses in Latin letters: “Καλοκαιρινά φορέματα” becomes kalokairina-foremata. Existing addresses don’t change.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Tested with WordPress 7.1
PHP
<?php

$greeklish = static function ( string $text ): string {
	$text = mb_strtolower( $text, 'UTF-8' );
	$text = strtr( $text, array( 'ου' => 'ou', 'ού' => 'ou' ) );
	return strtr(
		$text,
		array(
			'α' => 'a', 'ά' => 'a', 'β' => 'v', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'έ' => 'e',
			'ζ' => 'z', 'η' => 'i', 'ή' => 'i', 'θ' => 'th', 'ι' => 'i', 'ί' => 'i', 'ϊ' => 'i',
			'ΐ' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => 'x', 'ο' => 'o',
			'ό' => 'o', 'π' => 'p', 'ρ' => 'r', 'σ' => 's', 'ς' => 's', 'τ' => 't', 'υ' => 'y',
			'ύ' => 'y', 'ϋ' => 'y', 'ΰ' => 'y', 'φ' => 'f', 'χ' => 'ch', 'ψ' => 'ps', 'ω' => 'o',
			'ώ' => 'o',
		)
	);
};

add_filter(
	'sanitize_title',
	static function ( $title, $raw_title = '', $context = 'display' ) use ( $greeklish ) {
		if ( 'save' === $context && preg_match( '/\p{Greek}/u', (string) $title ) ) {
			return $greeklish( (string) $title );
		}
		return $title;
	},
	5,
	3
);

In these packs

  • Greek e-shop: For shops in Greece: receipt or invoice with a checked VAT number (ΑΦΜ), Greek phone and postcode checks, a cash on delivery fee, and greeklish addresses.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.