I need to replace some characters in my entry's URI because we have some letters which do not exist in English like "ş" or "ç". It is a problem for SEO and we have to change each time manually. I tried something with entries.onBeforeSaveEntry but I couldn't solve the problem. I'm confused with getting URI and set the new URI. Any suggestion?

  • I think you may have to use the "After save entry" event to change a URI.
    – JMKelley
    May 23 '19 at 10:58

I solved like this, maybe any of you will use with different types of it.

craft()->on('entries.onBeforeSaveEntry', function(Event $event) {
  $entry = $event->params['entry'];
  $turkishCharacters = ['ı', 'ü', 'ö', 'ş', 'ç', 'ğ'];
  $englishCharacters = ['i', 'u', 'o', 's', 'c', 'g'];

  $entrySlug = $entry->slug;
  $entrySlug = str_replace($turkishCharacters, $englishCharacters, $entrySlug);     
  $entry->slug = $entrySlug;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.