---
title: Custom handling of diacritics
related:
  - https://docs.kentico.com/13/developing-websites/implementing-routing/configuring-forbidden-url-characters.md
  - https://docs.kentico.com/13/developing-websites/implementing-routing/custom-routing-using-url-patterns/identifying-pages-based-on-url-parameters.md
  - https://docs.kentico.com/13/custom-development/handling-global-events.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

The system removes diacritics from text during many parsing operations. For example, diacritics are removed when indexing text for the [smart search](https://docs.kentico.com/13/configuring-xperience/setting-up-search-on-your-website.md) or when setting [page aliases](https://docs.kentico.com/13/developing-websites/implementing-routing/custom-routing-using-url-patterns/identifying-pages-based-on-url-parameters.md) or [URL slugs](https://docs.kentico.com/13/managing-website-content/working-with-pages/managing-page-urls.md) for pages. When the event is triggered, characters with diacritics are replaced by the appropriate base character, for example _ü_ is converted to _u_.

If you need to change the default behavior of removing diacritics, you can register and implement a handler for the **OnBeforeRemoveDiacritics** event.

The event is a member of the **TextHelper** class, which can be found under the **CMS.Helpers** namespace.

- The handler for this event has the source text included as a string parameter passed by reference, so any changes that you make in the code are reflected in the result.
- The handler has a _boolean_ return value that indicates whether the default functionality should also be performed after the handler is executed. For this reason, it is highly recommended to set the return value to _true_ for all but the most extensive customizations.

> **Warning:** **Warning**
>
> Only return a _false_ value if you are sure that your custom handler can take full responsibility for all diacritics removal requirements. Disabling the default system functionality may prevent parts of your website from working correctly.

## Example

The following example demonstrates how to define a handler for the diacritic removal event:

1. Open your Xperience solution in Visual Studio.
2. Create a [custom module class](https://docs.kentico.com/13/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md).
   - Add the class into a custom _Class Library_ project within the solution.
3. Override the module's **OnInit** method and assign the handler to the required event:

   ```csharp

   using System;

   using CMS;
   using CMS.DataEngine;
   using CMS.Helpers;

   // Registers the custom module into the system
   [assembly: RegisterModule(typeof(CustomDiacriticsModule))]

   public class CustomDiacriticsModule : Module
   {
       // Module class constructor, the system registers the module under the name "CustomDiacriticsHandling"
       public CustomDiacriticsModule()
           : base("CustomDiacriticsHandling")
       {
       }

       // Contains initialization code that is executed when the application starts
       protected override void OnInit()
       {
           base.OnInit();

           // Assigns a handler to the OnBeforeRemoveDiacritics event
           TextHelper.OnBeforeRemoveDiacritics += Custom_OnBeforeRemoveDiacritics;
       }
   }

   ```
4. Add the **Custom\_OnBeforeRemoveDiacritics** handler:

   ```csharp

   static bool Custom_OnBeforeRemoveDiacritics(ref string text, EventArgs e)
   {           
       // Replaces German special characters
       text = text.Replace( "ä", "ae" );
       text = text.Replace( "ö", "oe" );
       text = text.Replace( "ü", "ue" );
       text = text.Replace( "Ä", "Ae" );
       text = text.Replace( "Ö", "Oe" );
       text = text.Replace( "Ü", "Ue" );
       text = text.Replace( "ß", "ss" );

       // Returns true to indicate that the default diacritics removal should also be performed
       return true;                
   }

   ```

   > **Info:** This ensures that the system uses custom replacements for German special characters rather than simply stripping the diacritics and leaving the base character.
5. **Save** the file and Rebuild the solution.

The system applies the changes when removing diacritics from text.

> **Note:** **Note**: The customization does not automatically change the page aliases of existing pages until the current value is changed or saved.
