• Hello. I have this problem, my posts titles are in Greek language so the post slug is also in greek letters. Every time i change it manually ton english characters but i have this code that it will do it automatically. I do not know where to add it.
    Thank you.

    function title_slug( $title )
    {
    $slug = $title;
    
    $bad = array( '?','?','?','?','?','à','á','?','?','?','?','?','è','é','ê','?','ì','í','?','?','?',
    'ò','ó','?','?','?','?','ù','ú','?','ü','Y','à','á','a','?','?','?','?','è','é','ê',
    '?','ì','í','?','?','?','ò','ó','?','?','?','?','ù','ú','?','ü','y','?',
    'T','t','D','e','?','?','?','?','?','μ',
    '"',"'",'“','”',"\n","\r",'_');
    
    $good = array( 'S','Z','s','z','Y','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N',
    'O','O','O','O','O','O','U','U','U','U','Y','a','a','a','a','a','a','c','e','e','e',
    'e','i','i','i','i','n','o','o','o','o','o','o','u','u','u','u','y','y',
    'TH','th','DH','dh','ss','OE','oe','AE','ae','u',
    '','','','','','','-');
    
    // replace strange characters with alphanumeric equivalents
    $slug = str_replace( $bad, $good, $slug );
    
    $slug = trim($slug);
    
    // remove any duplicate whitespace, and ensure all characters are alphanumeric
    $bad_reg = array('/\s+/','/[^A-Za-z0-9\-]/');
    $good_reg = array('-','');
    $slug = preg_replace($bad_reg, $good_reg, $slug);
    
    // and lowercase
    $slug = strtolower($slug);
    
    return $slug;
    }
  • The topic ‘Locate the post slug function’ is closed to new replies.