Convert post slug's special chars to others automatically (i have the code) (2 posts)

  1. Nikolas
    Posted 5 years ago #

    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( 'Š','Ž','š','ž','Ÿ','À','Á','Â','Ã','Ä','Å','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ',
    $good = array( 'S','Z','s','z','Y','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N',
    // 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;
  2. Nikolas
    Posted 5 years ago #

    any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.