Skip to content

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

Greeklish file names for uploads

Uploaded files with Greek names get names in Latin letters (φωτογραφία.jpg becomes fotografia.jpg), so their addresses work everywhere.

  • 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_file_name',
	static function ( $filename ) use ( $greeklish ) {
		if ( ! preg_match( '/\p{Greek}/u', (string) $filename ) ) {
			return $filename;
		}
		$filename = preg_replace( '/[^a-z0-9._-]+/', '-', $greeklish( (string) $filename ) );
		return trim( preg_replace( '/-{2,}/', '-', $filename ), '-' );
	},
	5
);

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.